diff --git a/Array01.class b/Array01.class new file mode 100644 index 0000000..a734fa8 Binary files /dev/null and b/Array01.class differ diff --git a/Array01.java b/Array01.java new file mode 100644 index 0000000..0f65096 --- /dev/null +++ b/Array01.java @@ -0,0 +1,25 @@ +import java.util.Scanner; +public class Array01{ + public static void main(String [] args){ + Scanner sc = new Scanner(System.in); + + int i, num ; + System.out.print("Enter Length of Array: "); + num = sc.nextInt(); + + int [] arr = new int[num]; + System.out.println("Enter " + num + " Elements: "); + for (i = 0; i = 90){ + System.out.print("A"); + } else if (no >= 80){ + System.out.print("B"); + } else if (no >= 75){ + System.out.print("C"); + } else if (no < 50 || no > 100){ + System.out.print("Input Error"); + } else { + System.out.print("F"); + } + + } +} \ No newline at end of file diff --git a/Conversion.java b/Conversion.java new file mode 100644 index 0000000..a1f4216 --- /dev/null +++ b/Conversion.java @@ -0,0 +1,18 @@ +/** + * Data Type Conversion + */ +public class Conversion { + public static void main(String[] args) { + + //variable x is float data type + float x = 2.89f; + //variable y is an integer data type + int y = (int) x; + //float x will be convert to integer + System.out.println("Float to Int: " + y); + //displays y into integer + //output should be 2 + + } + +} \ No newline at end of file diff --git a/Conversion1.class b/Conversion1.class new file mode 100644 index 0000000..79ec8cb Binary files /dev/null and b/Conversion1.class differ diff --git a/Conversion1.java b/Conversion1.java new file mode 100644 index 0000000..03f723e --- /dev/null +++ b/Conversion1.java @@ -0,0 +1,13 @@ +public class Conversion1 { + public static void main (String[] args){ + final int grade = 80; + final int size = 20; + double final_grade = (double) grade; + double final_size = (double) size; + + //Displays final size and final grade variables + System.out.println(final_grade); + System.out.println(final_size); + + } +} \ No newline at end of file diff --git a/Conversion2.class b/Conversion2.class new file mode 100644 index 0000000..ca8fbf6 Binary files /dev/null and b/Conversion2.class differ diff --git a/Conversion2.java b/Conversion2.java new file mode 100644 index 0000000..361f44a --- /dev/null +++ b/Conversion2.java @@ -0,0 +1,11 @@ +public class Conversion2 { + public static void main (String[]main) { + String str = "1050"; + + int inum = Integer.parseInt(str); + System.out.println(inum); + + int onum = Integer.valueOf(str); + System.out.println(onum); + } +} \ No newline at end of file diff --git a/DoWhile1.class b/DoWhile1.class new file mode 100644 index 0000000..3358923 Binary files /dev/null and b/DoWhile1.class differ diff --git a/Exception01.class b/Exception01.class new file mode 100644 index 0000000..470be6a Binary files /dev/null and b/Exception01.class differ diff --git a/Exception01.java b/Exception01.java new file mode 100644 index 0000000..d22dabd --- /dev/null +++ b/Exception01.java @@ -0,0 +1,30 @@ +import java.util.*; +public class Exception01{ + public static void main(String [] args){ + Exception01 ex = new Exception01(); + ex.input(); + } + public void input(){ + Scanner sc = new Scanner(System.in); + int dividend, divisor, quotient; + System.out.print("Enter dividend: "); + dividend = sc.nextInt(); + System.out.print("Enter divisor: "); + divisor = sc.nextInt(); + try{ + quotient = dividend / divisor; + System.out.print(dividend + " / " + divisor + " = " + quotient); + } + catch(ArithmeticException e){ + System.out.println("Divisor cannot be 0"); + System.out.println("Try again."); + } + catch(InputMismatchException e){ + System.out.print("Wrong data type!"); + System.out.println("Try again."); + } + finally{ + System.out.println("\rThank you!"); + } + } +} \ No newline at end of file diff --git a/ForLoop1.class b/ForLoop1.class new file mode 100644 index 0000000..f4c7cef Binary files /dev/null and b/ForLoop1.class differ diff --git a/ForLoop1.java b/ForLoop1.java new file mode 100644 index 0000000..1db1890 --- /dev/null +++ b/ForLoop1.java @@ -0,0 +1,15 @@ +import java.util.Scanner; +public class ForLoop1 { + public static void main (String [] args){ + + Scanner sc = new Scanner(System.in); + int num; + + System.out.print("Enter a positive number: "); + num = sc.nextInt(); + + for (int i = 1; i<=10; i++){ + System.out.println(num + " x " + i + " = " + (num*i) ); + } + } +} \ No newline at end of file diff --git a/ForLoop2.class b/ForLoop2.class new file mode 100644 index 0000000..e01cc68 Binary files /dev/null and b/ForLoop2.class differ diff --git a/ForLoop2.java b/ForLoop2.java new file mode 100644 index 0000000..100c272 --- /dev/null +++ b/ForLoop2.java @@ -0,0 +1,20 @@ +import java.util.Scanner; +public class ForLoop2 { + public static void main(String [] args){ + int base, power; + int result = 1; + + Scanner sc = new Scanner(System.in); + + System.out.print("Enter the base number: "); + base = sc.nextInt(); + + System.out.print("Enter the power number: "); + power = sc.nextInt(); + + for(int i = 1; i<= power; i++){ + result *= base; + } + System.out.println("Result: " + result); + } +} \ No newline at end of file diff --git a/Hello.java b/Hello.java new file mode 100644 index 0000000..581e2f7 --- /dev/null +++ b/Hello.java @@ -0,0 +1,12 @@ +/** + * Hello + */ +public class Hello { + //main method + public static void main(String[] args) { + //Variable x is a string + String x = "Hello Arvin"; + //Says Hello Arvin + System.out.println(x); + } +} \ No newline at end of file diff --git a/Measurements.class b/Measurements.class new file mode 100644 index 0000000..5afe2be Binary files /dev/null and b/Measurements.class differ diff --git a/Measurements.java b/Measurements.java new file mode 100644 index 0000000..eafa70c --- /dev/null +++ b/Measurements.java @@ -0,0 +1,37 @@ +import java.util.Scanner; +public class Measurements{ + public static void main(String [] args){ + Scanner sc = new Scanner(System.in); + double num; + double cm = 0; + String measurement = ""; + String converter = ""; + + System.out.println("Available measurements are: millimeter (mm), centimeter (cm)"); + System.out.print("Enter a measurement: "); + measurement = measurement.toLowerCase(); + measurement = sc.nextLine(); + + System.out.print("Enter a number: "); + num = sc.nextDouble(); + + if(measurement.equals("mm")|| measurement.equals("millimeter")){ + + System.out.println("Available conversion to: centimeter (cm)"); + System.out.print("Convert number to: "); + converter = converter.toLowerCase(); + converter = sc.nextLine(); + + if(converter.equals("cm")||converter.equals("centimeter")){ + cm = num / cm; + System.out.println("Length in centimeter is: " + cm); + } else{ + System.out.println("Error, converter not found."); + } + } else if(measurement.equals("cm")|| measurement.equals("centimeter")){ + System.out.println("test"); + } else { + System.out.print("Error"); + } + } +} \ No newline at end of file diff --git a/MyLoopTest.class b/MyLoopTest.class new file mode 100644 index 0000000..9a7b59b Binary files /dev/null and b/MyLoopTest.class differ diff --git a/MyLoopTest.java b/MyLoopTest.java new file mode 100644 index 0000000..045027d --- /dev/null +++ b/MyLoopTest.java @@ -0,0 +1,11 @@ +import java.util.Scanner; +public class MyLoopTest { + public static void main(String [] args){ + int sum = 0; + for(int a=0; a<=100; a+=2){ + System.out.println(a); + //sum += a; + } + //System.out.print(sum); + } +} \ No newline at end of file diff --git a/Recursion07.java b/Recursion07.java new file mode 100644 index 0000000..292f35b --- /dev/null +++ b/Recursion07.java @@ -0,0 +1,37 @@ +import java.util.Scanner; +class Recursion07{ + public static void reverse(int arr[], int start, int end){ + if(start >= end) + return; + int temp; + temp = arr[start]; + arr[start] = arr[end]; + arr[end] = temp; + + reverse(arr, start+1, end-1); + } + + public static void main(String args[]){ + Scanner sc = new Scanner(System.in); + + System.out.println("Enter Row Array Elements: "); + int n = sc.nextInt(); + + System.out.println("Enter Array Elements: "); + int arr[] = new int[n]; + for(int i = 0; i= end) + return; + temp = arr[start]; + arr[start] = arr[end]; + arr[end] = temp; + rvereseArray(arr, start+1, end-1); + } + + /* Utility that prints out an array on a line */ + static void printArray(int arr[], int size) + { + for (int i=0; i < size; i++) + System.out.print(arr[i] + " "); + System.out.println(""); + } + + /*Driver function to check for above functions*/ + public static void main (String[] args) { + int arr[] = {7,10,55,100,49,60}; + printArray(arr, 6); + rvereseArray(arr, 0, 5); + System.out.println("Reversed array is "); + printArray(arr, 6); + } +} \ No newline at end of file diff --git a/StringArray.class b/StringArray.class new file mode 100644 index 0000000..2ab239a Binary files /dev/null and b/StringArray.class differ diff --git a/StringArray1.class b/StringArray1.class new file mode 100644 index 0000000..497ba0e Binary files /dev/null and b/StringArray1.class differ diff --git a/StringArray1.java b/StringArray1.java new file mode 100644 index 0000000..a68a607 --- /dev/null +++ b/StringArray1.java @@ -0,0 +1,20 @@ +import java.util.Arrays; +import java.util.Scanner; +public class StringArray1{ + public static void main(String[] args){ + Scanner sc = new Scanner(System.in)AA; + + String [] names = new String[5]; + System.out.println("Enter 5 Names:"); + for(int i = 0; i