├── AlphaPatterns ├── alpha1.java ├── alpha2.java ├── alpha3.java ├── alpha4.java ├── alpha5.java ├── alpha6.java ├── alpha7.java ├── alpha8.java ├── alpha9.java ├── pat1.java ├── pat2.java ├── pat3.java ├── pat4.java └── pat5.java ├── Arrays ├── addingel.java ├── addingelements.java ├── average.java ├── declaration.java ├── funprob1.java ├── funprob2.java ├── funprob3.java ├── largest.java ├── printingarray.java └── sumofelements.java ├── BinarySearch ├── binarymain.java ├── binaryyyclass.java ├── bs.java └── bsf.java ├── Conditionals ├── Largest.java ├── checkdigit.java ├── evenodd.java ├── ifst.java ├── leapyear.java ├── ternvoting.java ├── voting.java └── vowels.java ├── DW ├── fact.java ├── otn.java ├── oton.java ├── positivesum.java └── sumofn.java ├── FUNPROBLEMS ├── funprob1.java ├── funprob2.java ├── funprob3.java ├── funprob4.java ├── funprob5.java ├── funprob6.java ├── funprob8.java ├── funprob9.java ├── funproblem7.java └── tiddle.java ├── ForLoops ├── Amicable.java ├── fact.java ├── fibonacci.java ├── fornst.java ├── forst.java ├── mult.java ├── star.java ├── sumofn.java └── test.java ├── Functions ├── avg.java ├── countvowels.java ├── logic.java └── sumofdigits.java ├── HundredQuestions ├── Question1.java ├── Question2.java ├── Question3.java ├── Question4.java ├── question10.java ├── question11.java ├── question12.java ├── question13.java ├── question14.java ├── question15.java ├── question16.java ├── question17.java ├── question18.java ├── question19.java ├── question20.java ├── question21.java ├── question22.java ├── question23.java ├── question24.java ├── question25.java ├── question26.java ├── question27.java ├── question28.java ├── question29.java ├── question30.java ├── question5.java ├── question6.java ├── question7.java ├── question8.java └── question9.java ├── LinearSearch ├── LS.java ├── finalarray.java ├── lstemp.java ├── stringarray.java └── userarray.java ├── Multiarray ├── clone.java ├── intro.java ├── intro2.java ├── matrixadd.java ├── methodret.java ├── multi1.java └── outboundexcep.java ├── NumberPatterns ├── number1.java ├── number2.java ├── number3.java ├── number4.java ├── number5.java ├── number6.java └── number7.java ├── Operators ├── Fnc.java ├── arith.java ├── logical.java └── relational.java ├── Patterns ├── star1.java ├── star10.java ├── star11.java ├── star12.java ├── star13.java ├── star14.java ├── star2.java ├── star3.java ├── star4.java ├── star5.java ├── star6.java ├── star7.java ├── star8.java └── star9.java ├── README.md ├── Revision1 ├── decstar.java ├── hillstar.java └── starconcept.java ├── While ├── fact.java ├── fibonacci.java ├── gcd.java ├── hcf.java ├── lcm.java ├── multi.java ├── otn.java ├── positive.java └── ten.java ├── helloworld.java ├── loops ├── dowhilest.java └── whilest.java └── stringsss ├── sample.java └── strtodate.java /AlphaPatterns/alpha1.java: -------------------------------------------------------------------------------- 1 | package AlphaPatterns; 2 | 3 | public class alpha1 { 4 | public static void main(String[] args) { 5 | for (int i = 1; i <= 5; i++) { 6 | for (int j = 1; j <= i; j++) { 7 | System.out.print("A"); 8 | } 9 | System.out.println(); 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /AlphaPatterns/alpha2.java: -------------------------------------------------------------------------------- 1 | package AlphaPatterns; 2 | 3 | public class alpha2 { 4 | public static void main(String[] args) { 5 | for (int i = 1, p = 'A'; i <= 5; i++, p++) { 6 | for (int j = 1; j <= i; j++) { 7 | System.out.print((char) p); 8 | } 9 | System.out.println(); 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /AlphaPatterns/alpha3.java: -------------------------------------------------------------------------------- 1 | package AlphaPatterns; 2 | 3 | public class alpha3 { 4 | public static void main(String[] args) { 5 | for (int i = 1, p = 'E'; i <= 5; i++, p--) { 6 | for (int j = 1; j <= i; j++) { 7 | System.out.print((char) p); 8 | } 9 | System.out.println(); 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /AlphaPatterns/alpha4.java: -------------------------------------------------------------------------------- 1 | package AlphaPatterns; 2 | 3 | public class alpha4 { 4 | public static void main(String[] args) { 5 | for (int i = 1, p = 'A'; i <= 5; i++, p = p + 2) { 6 | for (int j = 1; j <= i; j++) { 7 | System.out.print((char) p); 8 | } 9 | System.out.println(); 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /AlphaPatterns/alpha5.java: -------------------------------------------------------------------------------- 1 | package AlphaPatterns; 2 | 3 | public class alpha5 { 4 | public static void main(String[] args) { 5 | 6 | for (int i = 1; i <= 5; i++) { 7 | int p = 'A'; 8 | for (int j = 1; j <= i; j++) { 9 | System.out.print((char) p++ + " "); 10 | } 11 | System.out.println(); 12 | 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /AlphaPatterns/alpha6.java: -------------------------------------------------------------------------------- 1 | package AlphaPatterns; 2 | 3 | public class alpha6 { 4 | public static void main(String[] args) { 5 | int p = 'A'; 6 | for (int i = 1; i <= 5; i++) { 7 | 8 | for (int j = 1; j <= i; j++) { 9 | System.out.print((char) p++ + " "); 10 | } 11 | System.out.println(); 12 | 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /AlphaPatterns/alpha7.java: -------------------------------------------------------------------------------- 1 | package AlphaPatterns; 2 | 3 | public class alpha7 { 4 | public static void main(String[] args) { 5 | for (int i = 1; i <= 5; i++) { 6 | int p = 'A'; 7 | for (int j = 1; j <= i; j++) { 8 | System.out.print(" "); 9 | } 10 | for (int k = i; k <= 5; k++) { 11 | System.out.print((char) p++ + " "); 12 | } 13 | System.out.println(); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /AlphaPatterns/alpha8.java: -------------------------------------------------------------------------------- 1 | package AlphaPatterns; 2 | 3 | public class alpha8 { 4 | public static void main(String[] args) { 5 | for (int i = 1; i <= 5; i++) { 6 | int p = 'A'; 7 | for (int j = 1; j <= i; j++) { 8 | System.out.print(" "); 9 | } 10 | for (int k = i; k <= 5; k++) { 11 | System.out.print((char) p++ + ""); 12 | } 13 | System.out.println(); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /AlphaPatterns/alpha9.java: -------------------------------------------------------------------------------- 1 | package AlphaPatterns; 2 | 3 | public class alpha9 { 4 | public static void main(String[] args) { 5 | for (int i = 1; i <= 5; i++) { 6 | int p = 'A'; 7 | for (int j = i; j <= 5; j++) { 8 | System.out.print((char) p++ + ""); 9 | } 10 | System.out.println(); 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /AlphaPatterns/pat1.java: -------------------------------------------------------------------------------- 1 | package AlphaPatterns; 2 | 3 | public class pat1 { 4 | public static void main(String[] args) { 5 | for (int i = 1; i <= 5; i++) { 6 | for (int j = 1; j <= i; j++) { 7 | System.out.print("*"); 8 | } 9 | System.out.println(); 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /AlphaPatterns/pat2.java: -------------------------------------------------------------------------------- 1 | package AlphaPatterns; 2 | 3 | public class pat2 { 4 | public static void main(String[] args) { 5 | for (int i = 1; i <= 5; i++) { 6 | for (int j = i; j <= 5; j++) { 7 | System.out.print("*"); 8 | } 9 | System.out.println(); 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /AlphaPatterns/pat3.java: -------------------------------------------------------------------------------- 1 | package AlphaPatterns; 2 | 3 | public class pat3 { 4 | public static void main(String[] args) { 5 | for (int i = 1; i <= 5; i++) { 6 | for (int j = 1; j <= i; j++) { 7 | System.out.print(" "); 8 | } 9 | for (int k = i; k <= 5; k++) { 10 | System.out.print("*"); 11 | } 12 | System.out.println(); 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /AlphaPatterns/pat4.java: -------------------------------------------------------------------------------- 1 | package AlphaPatterns; 2 | 3 | public class pat4 { 4 | public static void main(String[] args) { 5 | for (int i = 1; i <= 5; i++) { 6 | for (int j = i; j <= 5; j++) { 7 | System.out.print(" "); 8 | } 9 | for (int k = 1; k <= i; k++) { 10 | System.out.print("*"); 11 | } 12 | for (int l = 1; l <= i - 1; l++) { 13 | System.out.print("*"); 14 | } 15 | System.out.println(); 16 | } 17 | } 18 | } -------------------------------------------------------------------------------- /AlphaPatterns/pat5.java: -------------------------------------------------------------------------------- 1 | package AlphaPatterns; 2 | 3 | public class pat5 { 4 | public static void main(String[] args) { 5 | for (int i = 1; i <= 5; i++) { 6 | for (int j = i; j <= 5; j++) { 7 | System.out.print(" "); 8 | } 9 | for (int k = 1; k <= i; k++) { 10 | System.out.print("*"); 11 | } 12 | for (int l = 1; l <= i - 1; l++) { 13 | System.out.print("*"); 14 | } 15 | System.out.println(); 16 | } 17 | for (int i = 2; i <= 5; i++) { 18 | for (int j = 1; j <= i; j++) { 19 | System.out.print(" "); 20 | } 21 | for (int k = i; k <= 5; k++) { 22 | System.out.print("*"); 23 | } 24 | for (int l = i; l <= 4; l++) { 25 | System.out.print("*"); 26 | } 27 | System.out.println(); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Arrays/addingel.java: -------------------------------------------------------------------------------- 1 | package Arrays; 2 | 3 | import java.util.Scanner; 4 | 5 | public class addingel { 6 | public static void main(String[] args) { 7 | Scanner sc = new Scanner(System.in); 8 | int n; 9 | System.out.println("Enter the size of the array : "); 10 | n = sc.nextInt(); 11 | int arr[] = new int[n]; 12 | 13 | System.out.println("Enter the " + n + " elements of the array : "); 14 | for (int i = 0; i < n; i++) { 15 | arr[i] = sc.nextInt(); 16 | } 17 | System.out.println("The array entered is as follows : "); 18 | for (int i = 0; i < n; i++) { 19 | System.out.print(arr[i] + " "); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Arrays/addingelements.java: -------------------------------------------------------------------------------- 1 | package Arrays; 2 | 3 | import java.util.Scanner; 4 | 5 | public class addingelements { 6 | public static void main(String[] args) { 7 | Scanner sc = new Scanner(System.in); 8 | 9 | int arr[] = new int[10]; 10 | 11 | System.out.println("Enter the 10 elements of the arrays : "); 12 | for (int i = 0; i < 10; i++) { 13 | arr[i] = sc.nextInt(); 14 | } 15 | System.out.println("array full!"); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Arrays/average.java: -------------------------------------------------------------------------------- 1 | package Arrays; 2 | 3 | public class average { 4 | public static void main(String[] args) { 5 | int[] arr = new int[] { 50, 25, 60, 78, 100, 69, 92, 75, 98, 63 }; 6 | int sum = 0; 7 | for (int num : arr) { 8 | sum += num; 9 | } 10 | int avg = sum / arr.length; 11 | System.out.println("The sum of the elements of the array are : " + sum); 12 | System.out.println("The number of elements in the array are : " + arr.length); 13 | System.out.println("The average of the numbers is : " + avg); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Arrays/declaration.java: -------------------------------------------------------------------------------- 1 | package Arrays; 2 | 3 | public class declaration { 4 | public static void main(String[] args) { 5 | int[] arr = new int[] { 1, 2, 3, 4, 5 }; 6 | System.out.println(arr[2]); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /Arrays/funprob1.java: -------------------------------------------------------------------------------- 1 | package Arrays; 2 | 3 | public class funprob1 { 4 | public static void main(String[] args) { 5 | int arr[] = new int[5]; 6 | System.out.println(arr[0]); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /Arrays/funprob2.java: -------------------------------------------------------------------------------- 1 | package Arrays; 2 | 3 | public class funprob2 { 4 | public static void main(String[] args) { 5 | char charray[] = new char[15]; 6 | System.out.println(charray[15]); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /Arrays/funprob3.java: -------------------------------------------------------------------------------- 1 | package Arrays; 2 | 3 | public class funprob3 { 4 | public static void main(String[] args) { 5 | boolean arr[] = new boolean[5]; 6 | System.out.println(arr[0]); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /Arrays/largest.java: -------------------------------------------------------------------------------- 1 | package Arrays; 2 | 3 | public class largest { 4 | public static void main(String[] args) { 5 | int arr[] = new int[] { 10, 20, 30, 40, 50, 60, 70, 80, 90 }; 6 | int largest = arr[0]; 7 | for (int num : arr) { 8 | if (largest < num) { 9 | largest = num; 10 | } 11 | } 12 | System.out.println("The largest element inn the array is : " + largest); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Arrays/printingarray.java: -------------------------------------------------------------------------------- 1 | package Arrays; 2 | 3 | public class printingarray { 4 | public static void main(String[] args) { 5 | int[] array = new int[] { 1, 2, 3, 4, 5, 6 }; 6 | for (int elem : array) { 7 | System.out.println(elem); 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Arrays/sumofelements.java: -------------------------------------------------------------------------------- 1 | package Arrays; 2 | 3 | public class sumofelements { 4 | public static void main(String[] args) { 5 | int[] arr = new int[] { 10, 20, 30, 40, 50, 60 }; 6 | int sum = 0; 7 | for (int i = 0; i < arr.length; i++) { 8 | sum += arr[i]; 9 | } 10 | System.out.println("The sum of all the elements of the array is : " + sum); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /BinarySearch/binarymain.java: -------------------------------------------------------------------------------- 1 | package BinarySearch; 2 | 3 | import java.util.Scanner; 4 | 5 | public class binarymain { 6 | public static void main(String[] args) { 7 | Scanner sc = new Scanner(System.in); 8 | System.out.println("Enter the size of the array : "); 9 | int n = sc.nextInt(); 10 | int arr[] = new int[n]; 11 | 12 | System.out.println("Enter the " + n + " elements of the array : "); 13 | for (int i = 0; i < n; i++) { 14 | arr[i] = sc.nextInt(); 15 | } 16 | 17 | System.out.println("The array entered is as follows : "); 18 | for (int i = 0; i < n; i++) { 19 | System.out.println(arr[i] + " "); 20 | } 21 | 22 | System.out.println("Enter the element you want to search : "); 23 | int search = sc.nextInt(); 24 | int li = 0; 25 | int hi = arr.length - 1; 26 | int mi = (li + hi) / 2; 27 | while (li <= hi) { 28 | if (arr[mi] == search) { 29 | System.out.println(search + " was Found at : " + (mi + 1)); 30 | break; 31 | } else if (arr[mi] < search) { 32 | li = mi + 1; 33 | } else { 34 | hi = mi - 1; 35 | } 36 | mi = (li + hi) / 2; 37 | } 38 | if (li > hi) { 39 | System.out.println(search + " was Not Found"); 40 | } 41 | 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /BinarySearch/binaryyyclass.java: -------------------------------------------------------------------------------- 1 | // BINARY SEARCH USING BINARY CLASS IN JAVA 2 | 3 | package BinarySearch; 4 | 5 | import java.util.*; 6 | 7 | public class binaryyyclass { 8 | public static void main(String[] args) { 9 | int arr[] = { 12, 34, 56, 78, 89, 129, 234 }; 10 | int key = 78; 11 | int result = Arrays.binarySearch(arr, key); 12 | if (result < 0) { 13 | System.out.println("Item not found"); 14 | } else { 15 | System.out.println("Found at : " + (result + 1)); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /BinarySearch/bs.java: -------------------------------------------------------------------------------- 1 | package BinarySearch; 2 | 3 | public class bs { 4 | public static void main(String[] args) { 5 | int arr[] = { 4, 7, 12, 16, 18, 19, 81, 100, 131 }; 6 | int search = 81; 7 | int li = 0; 8 | int hi = arr.length - 1; 9 | int mi = (li + hi) / 2; 10 | while (li <= hi) { 11 | if (arr[mi] == search) { 12 | System.out.println("Item Found at : " + (mi + 1)); 13 | break; 14 | } else if (arr[mi] < search) { 15 | li = mi + 1; 16 | } else { 17 | hi = mi - 1; 18 | } 19 | mi = (li + hi) / 2; 20 | } 21 | if (li > hi) { 22 | System.out.println("Item Not Found"); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /BinarySearch/bsf.java: -------------------------------------------------------------------------------- 1 | package BinarySearch; 2 | 3 | public class bsf { 4 | static void binarysear(int arr[], int first, int last, int search) { 5 | int mid = (first + last) / 2; 6 | while (first <= last) { 7 | if (arr[mid] == search) { 8 | System.out.println("Found at : " + (mid + 1)); 9 | break; 10 | } 11 | 12 | else if (arr[mid] < search) { 13 | first = mid + 1; 14 | } else { 15 | last = mid - 1; 16 | } 17 | mid = (first + last) / 2; 18 | } 19 | if (first > last) { 20 | System.out.println("Item not found"); 21 | } 22 | } 23 | 24 | public static void main(String[] args) { 25 | int arr[] = new int[] { 1, 2, 3, 7, 11, 13, 14, 15, 90, 91, 100 }; 26 | int search = 547989; 27 | int last = arr.length - 1; 28 | binarysear(arr, 0, last, search); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Conditionals/Largest.java: -------------------------------------------------------------------------------- 1 | package Conditionals; 2 | 3 | import java.util.Scanner; 4 | 5 | public class Largest { 6 | public static void main(String[] args) { 7 | Scanner sc = new Scanner(System.in); 8 | 9 | int a = sc.nextInt(); 10 | int b = sc.nextInt(); 11 | int c = sc.nextInt(); 12 | 13 | if(a>=b&&a>=c){ 14 | System.out.println("the greatest number is "+a); 15 | 16 | } 17 | else if(b>=a&&b>=c){ 18 | 19 | System.out.println("the greatest number is "+b); 20 | 21 | } 22 | else{ 23 | System.out.println("the greatest number is "+c); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Conditionals/checkdigit.java: -------------------------------------------------------------------------------- 1 | package Conditionals; 2 | 3 | import java.util.Scanner; 4 | 5 | public class checkdigit { 6 | public static void main(String[] args) { 7 | Scanner sc = new Scanner(System.in); 8 | 9 | int a = sc.nextInt(); 10 | 11 | if(a<10){ 12 | System.out.println("This is a single digit number"); 13 | return; 14 | } 15 | if(a>=10&&a<100){ 16 | System.out.println("This is a double digit number"); 17 | return; 18 | } 19 | System.out.println("This is a three digit number"); 20 | 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Conditionals/evenodd.java: -------------------------------------------------------------------------------- 1 | package Conditionals; 2 | 3 | import java.util.Scanner; 4 | 5 | public class evenodd { 6 | public static void main(String[] args) { 7 | Scanner sc = new Scanner(System.in); 8 | 9 | int a = sc.nextInt(); 10 | int rem = a%2; 11 | 12 | if(rem==0){ 13 | System.out.println("This is an Even Number"); 14 | } 15 | else{ 16 | System.out.println("This is an Odd Number"); 17 | } 18 | System.out.println("Our Code Is Executed");; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Conditionals/ifst.java: -------------------------------------------------------------------------------- 1 | package Conditionals; 2 | import java.util.Scanner; 3 | public class ifst { 4 | public static void main(String[] args) { 5 | Scanner sc = new Scanner(System.in); 6 | 7 | int a = sc.nextInt(); 8 | 9 | if(a>10){ 10 | if(a>20){ 11 | System.out.println("number is greater than 20"); 12 | } 13 | else{ 14 | System.out.println("Number is greater than 10 but less than 20"); 15 | } 16 | } 17 | else{ 18 | System.out.println("Number is less than 10"); 19 | } 20 | 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Conditionals/leapyear.java: -------------------------------------------------------------------------------- 1 | package Conditionals; 2 | 3 | import java.util.Scanner; 4 | 5 | public class leapyear { 6 | public static void main(String[] args) { 7 | Scanner sc = new Scanner(System.in); 8 | 9 | int year = sc.nextInt(); 10 | boolean leap = false; 11 | 12 | if(year % 4 == 0){ 13 | 14 | if(year % 100 == 0){ 15 | 16 | if(year % 400 == 0){ 17 | leap = true; 18 | } 19 | else{ 20 | leap = false; 21 | } 22 | 23 | } 24 | else { 25 | leap =true; 26 | } 27 | } 28 | else { 29 | leap = false; 30 | } 31 | 32 | if(leap){ 33 | System.out.println("The year is a leap year!"); 34 | } 35 | else{ 36 | System.out.println("The year is not a leap year"); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Conditionals/ternvoting.java: -------------------------------------------------------------------------------- 1 | package Conditionals; 2 | 3 | import java.util.Scanner; 4 | 5 | public class ternvoting { 6 | public static void main(String[] args) { 7 | Scanner sc = new Scanner(System.in); 8 | 9 | int age = sc.nextInt(); 10 | 11 | String result = (age>18) ? ("Eligible") : ("Not Eligible"); 12 | System.out.println(result); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Conditionals/voting.java: -------------------------------------------------------------------------------- 1 | package Conditionals; 2 | 3 | import java.util.Scanner; 4 | 5 | public class voting { 6 | public static void main(String[] args) { 7 | Scanner sc = new Scanner(System.in); 8 | 9 | int age = sc.nextInt(); 10 | 11 | if(age>=18){ 12 | System.out.println("You are eligible to vote!"); 13 | } 14 | else{ 15 | System.out.println("Sorry You aren't eligible to vote!"); 16 | } 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /Conditionals/vowels.java: -------------------------------------------------------------------------------- 1 | package Conditionals; 2 | 3 | import java.util.Scanner; 4 | 5 | public class vowels { 6 | public static void main(String[] args) { 7 | Scanner sc = new Scanner(System.in); 8 | 9 | String a = sc.nextLine(); 10 | char c = a.charAt(0); 11 | 12 | switch(c){ 13 | case 'a': 14 | System.out.println("Vowel"); 15 | break; 16 | case 'e': 17 | System.out.println("Vowel"); 18 | break; 19 | case 'i': 20 | System.out.println("Vowel"); 21 | break; 22 | case 'o': 23 | System.out.println("Vowel"); 24 | break; 25 | case 'u': 26 | System.out.println("Vowel"); 27 | break; 28 | case 'A': 29 | System.out.println("Vowel"); 30 | break; 31 | case 'E': 32 | System.out.println("Vowel"); 33 | break; 34 | case 'I': 35 | System.out.println("Vowel"); 36 | break; 37 | case 'O': 38 | System.out.println("Vowel"); 39 | break; 40 | case 'U': 41 | System.out.println("Vowel"); 42 | break; 43 | default: 44 | System.out.println("Consonant"); 45 | } 46 | 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /DW/fact.java: -------------------------------------------------------------------------------- 1 | package DW; 2 | 3 | import java.util.Scanner; 4 | 5 | public class fact { 6 | public static void main(String[] args) { 7 | Scanner sc = new Scanner(System.in); 8 | int n = sc.nextInt(); 9 | int i = 1; 10 | int fact = 1; 11 | do { 12 | fact = fact * i; 13 | i++; 14 | } while (i <= n); 15 | System.out.println(fact); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /DW/otn.java: -------------------------------------------------------------------------------- 1 | package DW; 2 | 3 | public class otn { 4 | public static void main(String[] args) { 5 | int n = 10; 6 | int i = 1; 7 | do { 8 | System.out.print(i + " "); 9 | i++; 10 | } while (i <= n); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /DW/oton.java: -------------------------------------------------------------------------------- 1 | package DW; 2 | 3 | import java.util.Scanner; 4 | 5 | public class oton { 6 | public static void main(String[] args) { 7 | Scanner sc = new Scanner(System.in); 8 | 9 | int n = sc.nextInt(); 10 | int i = 1; 11 | do { 12 | System.out.print(i + " "); 13 | i++; 14 | } while (i <= n); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /DW/positivesum.java: -------------------------------------------------------------------------------- 1 | package DW; 2 | 3 | import java.util.Scanner; 4 | 5 | public class positivesum { 6 | public static void main(String[] args) { 7 | Scanner sc = new Scanner(System.in); 8 | int n = 0; 9 | int sum = 0; 10 | do { 11 | sum += n; 12 | System.out.println("Enter Numbers To be Added : "); 13 | n = sc.nextInt(); 14 | } while (n >= 0); 15 | System.out.println(sum); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /DW/sumofn.java: -------------------------------------------------------------------------------- 1 | package DW; 2 | 3 | import java.util.Scanner; 4 | 5 | public class sumofn { 6 | public static void main(String[] args) { 7 | Scanner sc = new Scanner(System.in); 8 | int n = sc.nextInt(); 9 | int i = 1; 10 | int sum = 0; 11 | do { 12 | sum += i; 13 | i++; 14 | } while (i <= n); 15 | System.out.println(sum); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /FUNPROBLEMS/funprob1.java: -------------------------------------------------------------------------------- 1 | package FUNPROBLEMS; 2 | 3 | public class funprob1 { 4 | public static void main(String[] args) { 5 | int x, y = 1; 6 | x = 10; 7 | if (x != 10 && x / 0 == 0) { 8 | System.out.println(y); 9 | } else { 10 | 11 | System.out.println(++y); 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /FUNPROBLEMS/funprob2.java: -------------------------------------------------------------------------------- 1 | package FUNPROBLEMS; 2 | 3 | public class funprob2 { 4 | public static void main(String[] args) { 5 | int x = 15; 6 | int y = x++; 7 | int z = ++x; 8 | System.out.println(y + " " + z); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /FUNPROBLEMS/funprob3.java: -------------------------------------------------------------------------------- 1 | package FUNPROBLEMS; 2 | 3 | public class funprob3 { 4 | public static void main(String[] args) { 5 | int x = 3; 6 | System.out.println(++x * 8); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /FUNPROBLEMS/funprob4.java: -------------------------------------------------------------------------------- 1 | package FUNPROBLEMS; 2 | 3 | public class funprob4 { 4 | public static void main(String[] args) { 5 | int x = 10; 6 | int y = 20; 7 | if (x++ > 10 && ++y > 20) { 8 | System.out.println("Inside if "); 9 | } else { 10 | System.out.println("Inside else "); 11 | } 12 | System.out.println(x + " " + y); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /FUNPROBLEMS/funprob5.java: -------------------------------------------------------------------------------- 1 | package FUNPROBLEMS; 2 | 3 | public class funprob5 { 4 | public static void main(String[] args) { 5 | int x = 10; 6 | int y = 20; 7 | if (x++ > 10 || ++y > 20) { 8 | System.out.println("Inside if "); 9 | } else { 10 | System.out.println("Inside Else "); 11 | } 12 | System.out.println(x + " " + y); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /FUNPROBLEMS/funprob6.java: -------------------------------------------------------------------------------- 1 | package FUNPROBLEMS; 2 | 3 | public class funprob6 { 4 | public static void main(String[] args) { 5 | for (int i = 0; i < 5; i++) { 6 | System.out.println(i + " "); 7 | i = i + 1; 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /FUNPROBLEMS/funprob8.java: -------------------------------------------------------------------------------- 1 | package FUNPROBLEMS; 2 | 3 | public class funprob8 { 4 | public static void main(String[] args) { 5 | int i = 1; 6 | while (i < 5) { 7 | if (i == 3) { 8 | break; 9 | } 10 | System.out.print(i + " "); 11 | i++; 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /FUNPROBLEMS/funprob9.java: -------------------------------------------------------------------------------- 1 | package FUNPROBLEMS; 2 | 3 | public class funprob9 { 4 | public static void main(String[] args) { 5 | int arr[] = new int[5]; 6 | arr[1] = 10; 7 | arr = new int[2]; 8 | System.out.println(arr[0]); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /FUNPROBLEMS/funproblem7.java: -------------------------------------------------------------------------------- 1 | package FUNPROBLEMS; 2 | 3 | public class funproblem7 { 4 | public static void main(String[] args) { 5 | for (int i = 0; i < 2; i++) { 6 | for (int j = 0; j < 2; j++) { 7 | if (j == 1) 8 | break; 9 | System.out.print(j + " "); 10 | } 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /FUNPROBLEMS/tiddle.java: -------------------------------------------------------------------------------- 1 | package FUNPROBLEMS; 2 | 3 | import java.util.Scanner; 4 | 5 | public class tiddle { 6 | public static void main(String[] args) { 7 | Scanner sc = new Scanner(System.in); 8 | int a = sc.nextInt(); 9 | int b = ~a; 10 | System.out.println(a + " " + b); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /ForLoops/Amicable.java: -------------------------------------------------------------------------------- 1 | package ForLoops; 2 | 3 | import java.util.Scanner; 4 | 5 | public class Amicable { 6 | public static void main(String[] args) { 7 | int firstDivisorSum = 0, secondDivisorSum = 0, firstNumber, secondNumber; 8 | Scanner sc = new Scanner(System.in); 9 | System.out.print("Enter the first number: "); 10 | 11 | firstNumber = sc.nextInt(); 12 | System.out.print("Enter the second number: "); 13 | 14 | secondNumber = sc.nextInt(); 15 | for (int i = 1; i < firstNumber; i++) { 16 | 17 | if (firstNumber % i == 0) { 18 | 19 | firstDivisorSum = firstDivisorSum + i; 20 | } 21 | } 22 | for (int i = 1; i < secondNumber; i++) { 23 | 24 | if (secondNumber % i == 0) { 25 | 26 | secondDivisorSum = secondDivisorSum + i; 27 | } 28 | } 29 | 30 | if ((firstNumber == secondDivisorSum) && (secondNumber == firstDivisorSum)) { 31 | System.out.println(firstNumber + ", " + secondNumber + " are amicable numbers."); 32 | } else { 33 | System.out.println(firstNumber + ", " + secondNumber + " are not amicable numbers."); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /ForLoops/fact.java: -------------------------------------------------------------------------------- 1 | package ForLoops; 2 | 3 | import java.util.Scanner; 4 | 5 | public class fact { 6 | public static void main(String[] args) { 7 | Scanner sc = new Scanner(System.in); 8 | 9 | int n = sc.nextInt(); 10 | int fact = 1; 11 | for (int i = 1; i <= n; i++) { 12 | fact = fact * i; 13 | } 14 | System.out.println("The factorial is " + fact); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /ForLoops/fibonacci.java: -------------------------------------------------------------------------------- 1 | package ForLoops; 2 | 3 | public class fibonacci { 4 | public static void main(String[] args) { 5 | int count = 10; 6 | int num1 = 0; 7 | int num2 = 1; 8 | System.out.println("Fibonacci series of " + count + " Numbers:"); 9 | 10 | for (int i = 1; i <= count; ++i) { 11 | System.out.print(num1 + " "); 12 | 13 | int sumofprev = num1 + num2; 14 | num1 = num2; 15 | num2 = sumofprev; 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /ForLoops/fornst.java: -------------------------------------------------------------------------------- 1 | package ForLoops; 2 | 3 | import java.util.Scanner; 4 | 5 | public class fornst { 6 | public static void main(String[] args) { 7 | Scanner sc = new Scanner(System.in); 8 | 9 | int n = sc.nextInt(); 10 | for (int i = 1; i <= n; i++) { 11 | System.out.println(i); 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /ForLoops/forst.java: -------------------------------------------------------------------------------- 1 | package ForLoops; 2 | 3 | public class forst { 4 | public static void main(String[] args) { 5 | for (int i = 1; i <= 10; i++) { 6 | System.out.println(i); 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /ForLoops/mult.java: -------------------------------------------------------------------------------- 1 | package ForLoops; 2 | 3 | import java.util.Scanner; 4 | 5 | public class mult { 6 | public static void main(String[] args) { 7 | Scanner sc = new Scanner(System.in); 8 | 9 | int n = sc.nextInt(); 10 | for (int i = 1; i <= 10; i++) { 11 | int mult = n * i; 12 | System.out.println(n + " * " + i + " = " + mult); 13 | } 14 | System.out.println("This is the end of the table!"); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /ForLoops/star.java: -------------------------------------------------------------------------------- 1 | package ForLoops; 2 | 3 | public class star { 4 | public static void main(String[] args) { 5 | for (int i = 1; i <= 5; i++) { 6 | for (int j = 1; j <= i; j++) { 7 | System.out.print("*"); 8 | } 9 | System.out.println(); 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /ForLoops/sumofn.java: -------------------------------------------------------------------------------- 1 | package ForLoops; 2 | 3 | import java.util.Scanner; 4 | 5 | public class sumofn { 6 | public static void main(String[] args) { 7 | Scanner sc = new Scanner(System.in); 8 | 9 | int n = sc.nextInt(); 10 | int sum = 0; 11 | 12 | for (int i = 1; i <= n; i++) { 13 | sum = sum + i; 14 | } 15 | System.out.println("the sum of give numbers is " + sum); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /ForLoops/test.java: -------------------------------------------------------------------------------- 1 | package ForLoops; 2 | 3 | public class test { 4 | public static void main(String[] args) { 5 | for (int i = 1; i < 5; i = i + 1) { 6 | System.out.print(i + " "); 7 | i = i - 1; 8 | } 9 | 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Functions/avg.java: -------------------------------------------------------------------------------- 1 | package Functions; 2 | 3 | import java.util.Scanner; 4 | 5 | public class avg { 6 | static double average(double a, double b, double c) { 7 | double d = (a + b + c) / 3; 8 | return d; 9 | } 10 | 11 | public static void main(String[] args) { 12 | Scanner sc = new Scanner(System.in); 13 | System.out.print("Enter Number 1 :"); 14 | double x = sc.nextDouble(); 15 | System.out.print("Enter Number 2 :"); 16 | double y = sc.nextDouble(); 17 | System.out.print("Enter Number 3 :"); 18 | double z = sc.nextDouble(); 19 | 20 | double p = average(x, y, z); 21 | System.out.println("Average of the three numbers is : " + p); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Functions/countvowels.java: -------------------------------------------------------------------------------- 1 | package Functions; 2 | 3 | import java.util.Scanner; 4 | 5 | public class countvowels { 6 | static int countvowels(String str) { 7 | int count = 0; 8 | for (int i = 0; i < str.length(); i++) { 9 | if (str.charAt(i) == 'a' || str.charAt(i) == 'e' || str.charAt(i) == 'i' || str.charAt(i) == 'o' 10 | || str.charAt(i) == 'u') { 11 | count++; 12 | } 13 | 14 | } 15 | return count; 16 | } 17 | 18 | public static void main(String[] args) { 19 | Scanner sc = new Scanner(System.in); 20 | System.out.print("Enter the string : "); 21 | String str = sc.nextLine(); 22 | 23 | int c = countvowels(str); 24 | System.out.println("The number of vowels in the given string are : " + c); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Functions/logic.java: -------------------------------------------------------------------------------- 1 | package Functions; 2 | 3 | public class logic { 4 | static int add(int x, int y) { 5 | int z; 6 | if (x > y) { 7 | z = x + y; 8 | } else { 9 | z = (x + y) * 6; 10 | } 11 | x = 560; 12 | return z; 13 | } 14 | 15 | public static void main(String[] args) { 16 | int a = 10; 17 | int b = 20; 18 | int c = add(a, b); 19 | System.out.println(c); 20 | 21 | int a1 = 40; 22 | int b1 = 60; 23 | int c1 = add(a1, b1); 24 | System.out.println(c1); 25 | 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Functions/sumofdigits.java: -------------------------------------------------------------------------------- 1 | package Functions; 2 | 3 | import java.util.Scanner; 4 | 5 | public class sumofdigits { 6 | static int sumofdigits(long n) { 7 | int rem = 0; 8 | while (n > 0) { 9 | rem += n % 10; 10 | n /= 10; 11 | } 12 | return rem; 13 | } 14 | 15 | public static void main(String[] args) { 16 | Scanner sc = new Scanner(System.in); 17 | 18 | System.out.print("Enter A Number : "); 19 | int a = sc.nextInt(); 20 | long b = sumofdigits(a); 21 | System.out.println("The sum of the digits is as follows : " + b); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /HundredQuestions/Question1.java: -------------------------------------------------------------------------------- 1 | package HundredQuestions; 2 | 3 | import java.util.Scanner; 4 | 5 | //FIBONACCI SERIES IN JAVA WITHOUT RECURSION 6 | public class Question1 { 7 | public static void main(String[] args) { 8 | Scanner sc = new Scanner(System.in); 9 | int n1 = 0; 10 | int n2 = 1; 11 | int n3; 12 | System.out.println("Enter the number of elements in the series : "); 13 | int count = sc.nextInt(); 14 | System.out.print(n1 + " " + n2); 15 | 16 | for (int i = 2; i < count; i++) { 17 | n3 = n1 + n2; 18 | System.out.print(" " + n3); 19 | n1 = n2; 20 | n2 = n3; 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /HundredQuestions/Question2.java: -------------------------------------------------------------------------------- 1 | package HundredQuestions; 2 | 3 | //FIBONACCI SERIES USING RECURSION 4 | public class Question2 { 5 | static int n1 = 0, n2 = 1, n3 = 0; 6 | 7 | static void fibonacci(int count) { 8 | if (count > 0) { 9 | n3 = n1 + n2; 10 | n1 = n2; 11 | n2 = n3; 12 | System.out.print(" " + n3); 13 | fibonacci(count - 1); 14 | } 15 | 16 | } 17 | 18 | public static void main(String[] args) { 19 | int count = 10; 20 | System.out.print(n1 + " " + n2); 21 | fibonacci(count - 2); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /HundredQuestions/Question3.java: -------------------------------------------------------------------------------- 1 | package HundredQuestions; 2 | //PRIME NUMBER PROGRAM IN JAVA 3 | 4 | import java.util.Scanner; 5 | 6 | public class Question3 { 7 | public static void main(String[] args) { 8 | int i, m = 0, flag = 0; 9 | Scanner sc = new Scanner(System.in); 10 | System.out.println("Enter the number to be checked : "); 11 | int n = sc.nextInt();// it is the number to be checked 12 | m = n / 2; 13 | if (n == 0 || n == 1) { 14 | System.out.println(n + " is not prime number"); 15 | } else { 16 | for (i = 2; i <= m; i++) { 17 | if (n % i == 0) { 18 | System.out.println(n + " is not prime number"); 19 | flag = 1; 20 | break; 21 | } 22 | } 23 | if (flag == 0) { 24 | System.out.println(n + " is prime number"); 25 | } 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /HundredQuestions/Question4.java: -------------------------------------------------------------------------------- 1 | package HundredQuestions; 2 | 3 | import java.util.Scanner; 4 | 5 | public class Question4 { 6 | public static void main(String[] args) { 7 | Scanner sc = new Scanner(System.in); 8 | int n = sc.nextInt(); 9 | int temp = n; 10 | int r; 11 | int sum = 0; 12 | while (n > 0) { 13 | r = n % 10; 14 | sum = (sum * 10) + r; 15 | n = n / 10; 16 | } 17 | if (temp == sum) { 18 | System.out.println("Palindrome"); 19 | } else { 20 | System.out.println("Not Palindrome"); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /HundredQuestions/question10.java: -------------------------------------------------------------------------------- 1 | package HundredQuestions; 2 | 3 | import java.util.Scanner; 4 | 5 | public class question10 { 6 | public static void main(String[] args) { 7 | Scanner sc = new Scanner(System.in); 8 | System.out.println("Enter two numbers"); 9 | int n = sc.nextInt(); 10 | int m = sc.nextInt(); 11 | int sum = n + m; 12 | System.out.println("Sum of the two numbers is : " + sum); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /HundredQuestions/question11.java: -------------------------------------------------------------------------------- 1 | package HundredQuestions; 2 | 3 | public class question11 { 4 | public static void main(String[] args) { 5 | float a = 1.0f; 6 | float b = 2.0f; 7 | 8 | float c = a * b; 9 | System.out.println("answer : " + c); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /HundredQuestions/question12.java: -------------------------------------------------------------------------------- 1 | package HundredQuestions; 2 | 3 | public class question12 { 4 | public static void main(String[] args) { 5 | char ch = 'a'; 6 | int ascii = ch; 7 | int cast = (int) ch; 8 | System.out.println("The ASCII value of " + ch + " is: " + ascii); 9 | System.out.println("The ASCII value of " + ch + " is: " + cast); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /HundredQuestions/question13.java: -------------------------------------------------------------------------------- 1 | package HundredQuestions; 2 | 3 | public class question13 { 4 | public static void main(String[] args) { 5 | int a = 99; 6 | int b = 5; 7 | int rem = a % b; 8 | int div = a / b; 9 | System.out.println(rem); 10 | System.out.println(div); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /HundredQuestions/question14.java: -------------------------------------------------------------------------------- 1 | package HundredQuestions; 2 | 3 | public class question14 { 4 | public static void main(String[] args) { 5 | int a = 100; 6 | int b = 45; 7 | System.out.println("--Before Swapping--"); 8 | System.out.println("first number = " + a); 9 | System.out.println("Second number = " + b); 10 | 11 | int temp = a; 12 | a = b; 13 | b = temp; 14 | System.out.println("--After Swapping--"); 15 | System.out.println("first number = " + a); 16 | System.out.println("Second number = " + b); 17 | 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /HundredQuestions/question15.java: -------------------------------------------------------------------------------- 1 | package HundredQuestions; 2 | 3 | import java.util.Scanner; 4 | 5 | public class question15 { 6 | public static void main(String[] args) { 7 | Scanner sc = new Scanner(System.in); 8 | System.out.println("Enter the number to be checked : "); 9 | int n = sc.nextInt(); 10 | if (n % 2 == 0) { 11 | System.out.println("Even"); 12 | } else { 13 | System.out.println("odd"); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /HundredQuestions/question16.java: -------------------------------------------------------------------------------- 1 | package HundredQuestions; 2 | 3 | import java.util.Scanner; 4 | 5 | public class question16 { 6 | public static void main(String[] args) { 7 | Scanner sc = new Scanner(System.in); 8 | System.out.println("Enter the alphabet : "); 9 | String s = sc.next(); 10 | 11 | char ch = s.charAt(0); 12 | 13 | if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u') { 14 | System.out.println("Vowel"); 15 | } else { 16 | System.out.println("Consonant"); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /HundredQuestions/question17.java: -------------------------------------------------------------------------------- 1 | package HundredQuestions; 2 | 3 | import java.util.Scanner; 4 | 5 | public class question17 { 6 | public static void main(String[] args) { 7 | Scanner sc = new Scanner(System.in); 8 | System.out.println("Enter the three numbers : "); 9 | int a = sc.nextInt(); 10 | int b = sc.nextInt(); 11 | int c = sc.nextInt(); 12 | 13 | if (a > b && a > c) { 14 | System.out.println(a + " is the greatest"); 15 | } 16 | 17 | else if (b > a && b > c) { 18 | System.out.println(b + " is the greatest"); 19 | } else { 20 | System.out.println(c + " is the greatest"); 21 | } 22 | 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /HundredQuestions/question18.java: -------------------------------------------------------------------------------- 1 | package HundredQuestions; 2 | 3 | import java.util.Scanner; 4 | 5 | public class question18 { 6 | public static void main(String[] args) { 7 | Scanner sc = new Scanner(System.in); 8 | System.out.println("Enter the 3 coefficients : "); 9 | double a = sc.nextDouble(); 10 | double b = sc.nextDouble(); 11 | double c = sc.nextDouble(); 12 | double root1; 13 | double root2; 14 | 15 | double D = b * b - 4 * a * c; 16 | 17 | if (D > 0) { 18 | root1 = (-b + Math.sqrt(D)) / (2 * a); 19 | root2 = (-b - Math.sqrt(D)) / (2 * a); 20 | System.out.format("root1 = %.2f and root2 = %.2f", root1, root2); 21 | } else if (D == 0) { 22 | root1 = root2 = -b / (2 * a); 23 | System.out.format("root1 = root2 = %.2f;", root1); 24 | 25 | } else { 26 | double real = -b / (2 * a); 27 | double imaginary = Math.sqrt(-D) / (2 * a); 28 | System.out.format("root1 = %.2f+%.2fi", real, imaginary); 29 | System.out.format("\nroot2 = %.2f-%.2fi", real, imaginary); 30 | } 31 | 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /HundredQuestions/question19.java: -------------------------------------------------------------------------------- 1 | package HundredQuestions; 2 | 3 | import java.util.Scanner; 4 | 5 | public class question19 { 6 | public static void main(String[] args) { 7 | Scanner sc = new Scanner(System.in); 8 | // year to be checked 9 | int year = sc.nextInt(); 10 | boolean leap = false; 11 | 12 | // if the year is divided by 4 13 | if (year % 4 == 0) { 14 | 15 | // if the year is century 16 | if (year % 100 == 0) { 17 | 18 | // if year is divided by 400 19 | // then it is a leap year 20 | if (year % 400 == 0) 21 | leap = true; 22 | else 23 | leap = false; 24 | } 25 | 26 | // if the year is not century 27 | else 28 | leap = true; 29 | } 30 | 31 | else 32 | leap = false; 33 | 34 | if (leap) 35 | System.out.println(year + " is a leap year."); 36 | else 37 | System.out.println(year + " is not a leap year."); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /HundredQuestions/question20.java: -------------------------------------------------------------------------------- 1 | package HundredQuestions; 2 | 3 | import java.util.Scanner; 4 | 5 | public class question20 { 6 | public static void main(String[] args) { 7 | Scanner sc = new Scanner(System.in); 8 | System.out.println("Enter a number : "); 9 | int n = sc.nextInt(); 10 | if (n > 0) { 11 | System.out.println("Positive Number"); 12 | } else if (n < 0) { 13 | System.out.println("Negative Number"); 14 | } else { 15 | System.out.println("The number is 0"); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /HundredQuestions/question21.java: -------------------------------------------------------------------------------- 1 | package HundredQuestions; 2 | 3 | public class question21 { 4 | public static void main(String[] args) { 5 | char c = '@'; 6 | if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) 7 | System.out.println(c + " is an alphabet."); 8 | else 9 | System.out.println(c + " is not an alphabet."); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /HundredQuestions/question22.java: -------------------------------------------------------------------------------- 1 | package HundredQuestions; 2 | 3 | import java.util.Scanner; 4 | 5 | public class question22 { 6 | public static void main(String[] args) { 7 | Scanner sc = new Scanner(System.in); 8 | int n = sc.nextInt(); 9 | int sum = 0; 10 | for (int i = 0; i <= n; i++) { 11 | sum = sum + i; 12 | } 13 | System.out.println("Sum : " + sum); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /HundredQuestions/question23.java: -------------------------------------------------------------------------------- 1 | package HundredQuestions; 2 | 3 | import java.util.Scanner; 4 | 5 | public class question23 { 6 | public static void main(String[] args) { 7 | Scanner sc = new Scanner(System.in); 8 | int n = sc.nextInt(); 9 | int fact = 1; 10 | 11 | for (int i = 1; i <= n; i++) { 12 | fact = fact * i; 13 | } 14 | System.out.println("Factorial of the given number is : " + fact); 15 | 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /HundredQuestions/question24.java: -------------------------------------------------------------------------------- 1 | package HundredQuestions; 2 | 3 | import java.util.Scanner; 4 | 5 | public class question24 { 6 | public static void main(String[] args) { 7 | Scanner sc = new Scanner(System.in); 8 | System.out.println("Enter two numbers : "); 9 | int a = sc.nextInt(); 10 | int b = sc.nextInt(); 11 | 12 | int gcd = 1; 13 | for (int i = 1; i <= a && i <= b; ++i) { 14 | 15 | // check if i perfectly divides both n1 and n2 16 | if (a % i == 0 && b % i == 0) 17 | gcd = i; 18 | } 19 | System.out.println("GCD of " + a + " and " + b + " is " + gcd); 20 | 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /HundredQuestions/question25.java: -------------------------------------------------------------------------------- 1 | package HundredQuestions; 2 | 3 | import java.util.Scanner; 4 | 5 | public class question25 { 6 | public static void main(String[] args) { 7 | Scanner sc = new Scanner(System.in); 8 | int a = sc.nextInt(); 9 | int b = sc.nextInt(); 10 | int lcm; 11 | lcm = (a > b) ? a : b; 12 | while (true) { 13 | if (lcm % a == 0 && lcm % b == 0) { 14 | System.out.printf("The LCM of %d and %d is %d.", a, b, lcm); 15 | break; 16 | } 17 | ++lcm; 18 | } 19 | 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /HundredQuestions/question26.java: -------------------------------------------------------------------------------- 1 | package HundredQuestions; 2 | 3 | public class question26 { 4 | public static void main(String[] args) { 5 | int a = 123456789; 6 | int count = 0; 7 | while (a != 0) { 8 | a /= 10; 9 | ++count; 10 | } 11 | System.out.println(count); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /HundredQuestions/question27.java: -------------------------------------------------------------------------------- 1 | package HundredQuestions; 2 | 3 | public class question27 { 4 | public static void main(String[] args) { 5 | int base = 12; 6 | int power = 5; 7 | int result = 1; 8 | while (power != 0) { 9 | result = result * base; 10 | --power; 11 | } 12 | System.out.println("Result : " + result); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /HundredQuestions/question28.java: -------------------------------------------------------------------------------- 1 | package HundredQuestions; 2 | 3 | public class question28 { 4 | public static void main(String[] args) { 5 | int a = 12; 6 | System.out.println("Factors of " + a + " are : "); 7 | for (int i = 1; i <= a; i++) { 8 | if (a % i == 0) { 9 | System.out.print(i + " "); 10 | } 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /HundredQuestions/question29.java: -------------------------------------------------------------------------------- 1 | package HundredQuestions; 2 | 3 | public class question29 { 4 | public static void main(String[] args) { 5 | int arr[] = { 44, 66, 11, 33, 99, 88, 77, 66, 34, 68, 35, 68, 34, 8, 77 }; 6 | int largest = arr[0]; 7 | for (int num : arr) { 8 | if (largest < num) { 9 | largest = num; 10 | } 11 | } 12 | System.out.println(largest); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /HundredQuestions/question30.java: -------------------------------------------------------------------------------- 1 | package HundredQuestions; 2 | 3 | import java.time.LocalDate; 4 | import java.time.format.DateTimeFormatter; 5 | 6 | public class question30 { 7 | public static void main(String[] args) { 8 | String string = "2021-07-30"; 9 | LocalDate date = LocalDate.parse(string, DateTimeFormatter.ISO_DATE); 10 | 11 | System.out.println("The Date is : " + date); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /HundredQuestions/question5.java: -------------------------------------------------------------------------------- 1 | package HundredQuestions; 2 | 3 | import java.util.Scanner; 4 | 5 | public class question5 { 6 | public static void main(String[] args) { 7 | Scanner sc = new Scanner(System.in); 8 | int n = sc.nextInt(); 9 | int rev = 0; 10 | while (n != 0) { 11 | int rem = n % 10; 12 | rev = rev * 10 + rem; 13 | n = n / 10; 14 | } 15 | System.out.println("The reversed number is : " + rev); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /HundredQuestions/question6.java: -------------------------------------------------------------------------------- 1 | package HundredQuestions; 2 | 3 | //FASCINATING NUMBER 4 | import java.util.Scanner; 5 | 6 | public class question6 { 7 | public static void main(String[] args) { 8 | Scanner sc = new Scanner(System.in); 9 | int n = sc.nextInt(); 10 | int n1 = n * 2; 11 | int n2 = n * 3; 12 | 13 | String combo = n + "" + n1 + n2; 14 | boolean search = true; 15 | for (char c = '1'; c <= '9'; c++) { 16 | int count = 0; 17 | for (int i = 0; i < combo.length(); i++) { 18 | char ch = combo.charAt(i); 19 | if (ch == c) 20 | count++; 21 | } 22 | if (count > 1 || count == 0) { 23 | search = false; 24 | break; 25 | } 26 | } 27 | if (search) { 28 | System.out.println("Fascinating Number"); 29 | } else { 30 | System.out.println("Not a Fascinating number"); 31 | } 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /HundredQuestions/question7.java: -------------------------------------------------------------------------------- 1 | package HundredQuestions; 2 | 3 | import java.util.Scanner; 4 | 5 | //BUZZ NUMBER 6 | public class question7 { 7 | public static void main(String[] args) { 8 | 9 | Scanner sc = new Scanner(System.in); 10 | int n = sc.nextInt(); 11 | if (n % 10 == 7 || n % 7 == 0) { 12 | System.out.println("Buzz Number"); 13 | } else { 14 | System.out.println("Not a buzz number"); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /HundredQuestions/question8.java: -------------------------------------------------------------------------------- 1 | package HundredQuestions; 2 | 3 | import java.util.Scanner; 4 | 5 | //DUCK NUMBER 6 | public class question8 { 7 | public static boolean checkNumber(int number) { 8 | 9 | // use loop to repeat steps 10 | while (number != 0) { 11 | 12 | // check whether the last digit of the number is zero or not 13 | if (number % 10 == 0) 14 | return true; // return true if the number is Duck 15 | 16 | // divide the number by 10 to remove the last digit 17 | number = number / 10; 18 | } 19 | 20 | return false; // return false if the number is not Duck 21 | } 22 | 23 | // main() method start 24 | public static void main(String args[]) { 25 | int n1, n2; 26 | 27 | // create scanner class object to get input from user 28 | Scanner sc = new Scanner(System.in); 29 | 30 | // show custom message 31 | System.out.println("Enter first number"); 32 | 33 | // store user entered value into variable n1 34 | n1 = sc.nextInt(); 35 | 36 | // show custom message 37 | System.out.println("Enter second number"); 38 | 39 | // store user entered value into variable n2 40 | n2 = sc.nextInt(); 41 | 42 | if (checkNumber(n1)) 43 | System.out.println(n1 + " is a Duck number"); 44 | else 45 | System.out.println(n1 + " is not a Duck number"); 46 | if (checkNumber(n2)) 47 | System.out.println(n2 + " is a Duck number"); 48 | else 49 | System.out.println(n2 + " is not a Duck number"); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /HundredQuestions/question9.java: -------------------------------------------------------------------------------- 1 | package HundredQuestions; 2 | 3 | import java.util.Scanner; 4 | 5 | //PRINTING AN INTEGER 6 | public class question9 { 7 | public static void main(String[] args) { 8 | Scanner sc = new Scanner(System.in); 9 | System.out.println("Enter a number"); 10 | int n = sc.nextInt(); 11 | System.out.println("Number enteref by you is : " + n); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /LinearSearch/LS.java: -------------------------------------------------------------------------------- 1 | package LinearSearch; 2 | 3 | public class LS { 4 | public static void main(String[] args) { 5 | int arr[] = { 1, 2, 3, 4, 5, 6 }; 6 | int search = 10; 7 | for (int i = 0; i < arr.length; i++) { 8 | if (arr[i] == search) { 9 | System.out.println("found at position : " + i); 10 | break; 11 | } 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /LinearSearch/finalarray.java: -------------------------------------------------------------------------------- 1 | package LinearSearch; 2 | 3 | import java.util.Scanner; 4 | 5 | public class finalarray { 6 | public static void main(String[] args) { 7 | Scanner sc = new Scanner(System.in); 8 | System.out.println("Enter the size of the array : "); 9 | int n = sc.nextInt(); 10 | int temp = 0; 11 | 12 | int arr[] = new int[n]; 13 | 14 | System.out.println("Enter the " + n + " elements in the array : "); 15 | for (int i = 0; i < n; i++) { 16 | arr[i] = sc.nextInt(); 17 | } 18 | 19 | System.out.println("Enter the element you want to search : "); 20 | int search = sc.nextInt(); 21 | 22 | for (int i = 0; i < n; i++) { 23 | if (arr[i] == search) { 24 | System.out.println(search + " was found at the position : " + (i + 1)); 25 | temp = temp + 1; 26 | break; 27 | } 28 | } 29 | if (temp == 0) { 30 | System.out.println("Element not found!"); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /LinearSearch/lstemp.java: -------------------------------------------------------------------------------- 1 | package LinearSearch; 2 | 3 | public class lstemp { 4 | public static void main(String[] args) { 5 | int arr[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9 }; 6 | int search = 10; 7 | int temp = 0; 8 | for (int i = 0; i < arr.length; i++) { 9 | if (arr[i] == search) { 10 | System.out.println("found at position : " + i); 11 | temp = temp + 1; 12 | } 13 | } 14 | if (temp == 0) { 15 | System.out.println("Element not found!"); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /LinearSearch/stringarray.java: -------------------------------------------------------------------------------- 1 | package LinearSearch; 2 | 3 | public class stringarray { 4 | public static void main(String[] args) { 5 | String arr[] = { "maseera", "hritvik", "tulasi", "vaasvi", "manoj", "ayush" }; 6 | String name = "Kabir"; 7 | int temp = 0; 8 | for (int i = 0; i < arr.length; i++) { 9 | if (arr[i].equals(name)) { 10 | System.out.println("Found at position : " + i); 11 | temp = temp + 1; 12 | } 13 | } 14 | if (temp == 0) { 15 | System.out.println("User not Found!"); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /LinearSearch/userarray.java: -------------------------------------------------------------------------------- 1 | package LinearSearch; 2 | 3 | import java.util.Scanner; 4 | 5 | public class userarray { 6 | public static void main(String[] args) { 7 | Scanner sc = new Scanner(System.in); 8 | int arr[] = new int[10]; 9 | int search = 10; 10 | int temp = 0; 11 | System.out.println("Enter 10 elements of the array : "); 12 | for (int i = 0; i < 10; i++) { 13 | arr[i] = sc.nextInt(); 14 | } 15 | 16 | for (int i = 0; i < 10; i++) { 17 | if (arr[i] == search) { 18 | System.out.println("found at : " + i); 19 | temp = temp + 1; 20 | } 21 | } 22 | if (temp == 0) { 23 | System.out.println("Element not found"); 24 | } 25 | 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Multiarray/clone.java: -------------------------------------------------------------------------------- 1 | package Multiarray; 2 | 3 | import java.util.Scanner; 4 | 5 | public class clone { 6 | public static void main(String[] args) { 7 | Scanner sc = new Scanner(System.in); 8 | System.out.println("Enter the size of the array : "); 9 | int n = sc.nextInt(); 10 | int arr[] = new int[n]; 11 | System.out.println("Enter the " + n + " elements of the array."); 12 | for (int i = 0; i < n; i++) { 13 | arr[i] = sc.nextInt(); 14 | } 15 | System.out.println("Printing original array:"); 16 | for (int i : arr) { 17 | System.out.print(i + " "); 18 | } 19 | System.out.println(); 20 | System.out.println("Printing clone of the array:"); 21 | int carr[] = arr.clone(); 22 | for (int i : carr) { 23 | System.out.print(i + " "); 24 | } 25 | 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Multiarray/intro.java: -------------------------------------------------------------------------------- 1 | package Multiarray; 2 | 3 | public class intro { 4 | public static void main(String[] args) { 5 | int arr[] = new int[5]; 6 | arr[0] = 10; 7 | arr[1] = 5; 8 | arr[2] = 7; 9 | arr[3] = 30; 10 | arr[4] = 50; 11 | int arr1[] = new int[5]; 12 | arr1[0] = 45; 13 | arr1[1] = 34; 14 | arr1[2] = 87; 15 | arr1[3] = 67; 16 | arr1[4] = 40; 17 | 18 | for (int i = 0; i < arr.length; i++) { 19 | System.out.print(arr[i] + " "); 20 | } 21 | System.out.println(); 22 | for (int i = 0; i < arr1.length; i++) { 23 | System.out.print(arr1[i] + " "); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Multiarray/intro2.java: -------------------------------------------------------------------------------- 1 | package Multiarray; 2 | 3 | public class intro2 { 4 | public static void main(String[] args) { 5 | int arr[] = { 5, 8, 12, 9, 36, 45, 78, 94, 673, 345 }; 6 | for (int i : arr) { 7 | System.out.print(i + " "); 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Multiarray/matrixadd.java: -------------------------------------------------------------------------------- 1 | package Multiarray; 2 | 3 | public class matrixadd { 4 | public static void main(String[] args) { 5 | int arr1[][] = { { 3, 3, 3 }, { 7, 14, 28 } }; 6 | int arr2[][] = { { 33, 60, 50 }, { 6, 12, 42 } }; 7 | 8 | int arr3[][] = new int[2][3]; 9 | for (int i = 0; i < 2; i++) { 10 | for (int j = 0; j < 3; j++) { 11 | arr3[i][j] = arr1[i][j] + arr2[i][j]; 12 | System.out.print(arr3[i][j] + " "); 13 | } 14 | System.out.println(); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Multiarray/methodret.java: -------------------------------------------------------------------------------- 1 | package Multiarray; 2 | 3 | public class methodret { 4 | 5 | static int[] arr() { 6 | return new int[] { 12, 56, 77, 99, 67, 88, 94, 35, 12, 32 }; 7 | } 8 | 9 | public static void main(String[] args) { 10 | int arr[] = arr(); 11 | 12 | for (int i : arr) { 13 | System.out.print(i + " "); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Multiarray/multi1.java: -------------------------------------------------------------------------------- 1 | package Multiarray; 2 | 3 | public class multi1 { 4 | public static void main(String[] args) { 5 | int arr[][] = { { 6, 12, 18 }, { 54, 65, 45 }, { 66, 67, 68 } }; 6 | for (int i = 0; i < 3; i++) { 7 | for (int j = 0; j < 3; j++) { 8 | System.out.print(arr[i][j] + " "); 9 | } 10 | System.out.println(); 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Multiarray/outboundexcep.java: -------------------------------------------------------------------------------- 1 | package Multiarray; 2 | 3 | public class outboundexcep { 4 | public static void main(String[] args) { 5 | int arr[] = { 87, 90, 95, 63, 9 }; 6 | 7 | for (int i = 0; i <= arr.length; i++) { 8 | System.out.println(arr[i]); 9 | } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /NumberPatterns/number1.java: -------------------------------------------------------------------------------- 1 | package NumberPatterns; 2 | 3 | public class number1 { 4 | public static void main(String[] args) { 5 | for (int i = 1; i <= 4; i++) { 6 | for (int j = 1; j <= i; j++) { 7 | System.out.print(j); 8 | } 9 | System.out.println(); 10 | } 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /NumberPatterns/number2.java: -------------------------------------------------------------------------------- 1 | package NumberPatterns; 2 | 3 | public class number2 { 4 | public static void main(String[] args) { 5 | for (int i = 4; i >= 1; i--) { 6 | for (int j = 1; j <= i; j++) { 7 | System.out.print(j); 8 | } 9 | System.out.println(); 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /NumberPatterns/number3.java: -------------------------------------------------------------------------------- 1 | package NumberPatterns; 2 | 3 | public class number3 { 4 | public static void main(String[] args) { 5 | for (int i = 1; i <= 4; i++) { 6 | for (int j = 1; j <= i; j++) { 7 | System.out.print(j); 8 | } 9 | System.out.println(); 10 | } 11 | for (int i = 3; i >= 1; i--) { 12 | for (int j = 1; j <= i; j++) { 13 | System.out.print(j); 14 | } 15 | System.out.println(); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /NumberPatterns/number4.java: -------------------------------------------------------------------------------- 1 | package NumberPatterns; 2 | 3 | public class number4 { 4 | public static void main(String[] args) { 5 | for (int i = 1; i <= 5; i++) { 6 | for (int j = 1; j <= i; j++) { 7 | System.out.print(i); 8 | } 9 | System.out.println(); 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /NumberPatterns/number5.java: -------------------------------------------------------------------------------- 1 | package NumberPatterns; 2 | 3 | public class number5 { 4 | public static void main(String[] args) { 5 | for (int i = 5; i >= 1; i--) { 6 | for (int j = 1; j <= i; j++) { 7 | System.out.print(j); 8 | } 9 | System.out.println(); 10 | } 11 | for (int i = 2; i <= 5; i++) { 12 | for (int j = 1; j <= i; j++) { 13 | System.out.print(j); 14 | } 15 | System.out.println(); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /NumberPatterns/number6.java: -------------------------------------------------------------------------------- 1 | package NumberPatterns; 2 | 3 | public class number6 { 4 | public static void main(String[] args) { 5 | for (int i = 1; i <= 5; i++) { 6 | for (int j = 5; j >= i; j--) { 7 | System.out.print(" "); 8 | } 9 | for (int k = 1; k <= i; k++) { 10 | System.out.print(k + " "); 11 | } 12 | System.out.println(); 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /NumberPatterns/number7.java: -------------------------------------------------------------------------------- 1 | package NumberPatterns; 2 | 3 | public class number7 { 4 | public static void main(String[] args) { 5 | for (int i = 1; i <= 5; i++) { 6 | for (int j = 5; j >= i; j--) { 7 | System.out.print(" "); 8 | } 9 | for (int k = 1; k <= i; k++) { 10 | System.out.print(k + " "); 11 | } 12 | System.out.println(); 13 | } 14 | for (int i = 1; i <= 5; i++) { 15 | for (int j = 1; j <= i; j++) { 16 | System.out.print(" "); 17 | } 18 | for (int k = 1; k <= 5 - i; k++) { 19 | System.out.print(" " + k); 20 | } 21 | System.out.println(); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Operators/Fnc.java: -------------------------------------------------------------------------------- 1 | package Operators; 2 | import java.util.Scanner; 3 | 4 | public class Fnc{ 5 | public static void main(String[] args) { 6 | Scanner sc = new Scanner(System.in); 7 | 8 | int f = sc.nextInt(); 9 | int c = (5*(f-32))/9; 10 | 11 | System.out.println(c); 12 | } 13 | } -------------------------------------------------------------------------------- /Operators/arith.java: -------------------------------------------------------------------------------- 1 | package Operators; 2 | public class arith { 3 | public static void main(String[] args) { 4 | int a =9; 5 | int b=5; 6 | 7 | char c = 'a'; 8 | int i = c+1; 9 | System.out.println(i); 10 | System.out.println(2/5); 11 | System.out.println('a'/'b'); 12 | // System.out.println(9/5); 13 | // System.out.println(9.0/5); 14 | // System.out.println(9+5); 15 | // System.out.println(9-5); 16 | // System.out.println(9*5); 17 | // System.out.println(9%5); 18 | // System.out.println('A'+1); 19 | // System.out.println('a'+'b'); 20 | 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Operators/logical.java: -------------------------------------------------------------------------------- 1 | package Operators; 2 | import java.util.Scanner; 3 | 4 | public class logical { 5 | public static void main(String[] args) { 6 | Scanner sc = new Scanner(System.in); 7 | 8 | int a =sc.nextInt(); 9 | int b =sc.nextInt(); 10 | int c = sc.nextInt(); 11 | 12 | boolean islargest = (a>=b)&&(a>=c); 13 | System.out.println(islargest); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Operators/relational.java: -------------------------------------------------------------------------------- 1 | package Operators; 2 | import java.util.Scanner; 3 | 4 | public class relational { 5 | public static void main(String[] args) { 6 | Scanner sc = new Scanner(System.in); 7 | 8 | int a = sc.nextInt(); 9 | int b = sc.nextInt(); 10 | 11 | boolean isEq = (a==b); 12 | boolean isneq = (a!=b); 13 | boolean gr = (a>b); 14 | boolean gre= (a>=b); 15 | boolean ls = (a= i; j--) { 7 | System.out.print(" "); 8 | } 9 | for (int k = 1; k <= i; k++) { 10 | System.out.print("*"); 11 | } 12 | for (int l = 2; l <= i; l++) { 13 | System.out.print("*"); 14 | } 15 | System.out.println(); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Patterns/star11.java: -------------------------------------------------------------------------------- 1 | package Patterns; 2 | 3 | public class star11 { 4 | public static void main(String[] args) { 5 | for (int i = 1; i <= 4; i++) { 6 | for (int j = 1; j <= i; j++) { 7 | System.out.print(" "); 8 | } 9 | for (int k = 4; k >= i; k--) { 10 | System.out.print("*"); 11 | } 12 | for (int l = 3; l >= i; l--) { 13 | System.out.print("*"); 14 | } 15 | System.out.println(); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Patterns/star12.java: -------------------------------------------------------------------------------- 1 | package Patterns; 2 | 3 | public class star12 { 4 | public static void main(String[] args) { 5 | for (int i = 1; i <= 4; i++) { 6 | for (int j = 1; j <= i; j++) { 7 | System.out.print(" "); 8 | } 9 | for (int k = 4; k >= i; k--) { 10 | System.out.print("*"); 11 | } 12 | System.out.println(); 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Patterns/star13.java: -------------------------------------------------------------------------------- 1 | package Patterns; 2 | 3 | public class star13 { 4 | public static void main(String[] args) { 5 | for (int i = 1; i <= 5; i++) { 6 | for (int j = 1; j <= i; j++) { 7 | if (i >= 2 && j <= i - 1) { 8 | System.out.print(" "); 9 | } else { 10 | System.out.print("*"); 11 | } 12 | } 13 | System.out.println(); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Patterns/star14.java: -------------------------------------------------------------------------------- 1 | package Patterns; 2 | 3 | public class star14 { 4 | public static void main(String[] args) { 5 | for (int i = 1; i <= 5; i++) { 6 | for (int j = 1; j <= i; j++) { 7 | System.out.print(" "); 8 | } 9 | for (int k = i; k <= 5; k++) { 10 | System.out.print("*"); 11 | } 12 | for (int l = i; l <= 4; l++) { 13 | System.out.print("*"); 14 | } 15 | System.out.println(); 16 | } 17 | for (int i = 2; i <= 5; i++) { 18 | for (int j = i; j <= 5; j++) { 19 | System.out.print(" "); 20 | } 21 | for (int k = 1; k <= i; k++) { 22 | System.out.print("*"); 23 | } 24 | for (int l = 1; l <= i - 1; l++) { 25 | System.out.print("*"); 26 | } 27 | System.out.println(); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Patterns/star2.java: -------------------------------------------------------------------------------- 1 | package Patterns; 2 | 3 | import javax.swing.plaf.synth.SynthOptionPaneUI; 4 | 5 | public class star2 { 6 | public static void main(String[] args) { 7 | for (int i = 1; i <= 4; i++) { 8 | for (int j = 4; j >= i; j--) { 9 | System.out.print("*"); 10 | } 11 | System.out.println(); 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Patterns/star3.java: -------------------------------------------------------------------------------- 1 | package Patterns; 2 | 3 | public class star3 { 4 | public static void main(String[] args) { 5 | for (int i = 1; i <= 4; i++) { 6 | for (int j = 1; j <= 4; j++) { 7 | System.out.print("*"); 8 | } 9 | System.out.println(); 10 | 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Patterns/star4.java: -------------------------------------------------------------------------------- 1 | package Patterns; 2 | 3 | public class star4 { 4 | public static void main(String[] args) { 5 | for (int i = 1; i <= 4; i++) { 6 | for (int j = 1; j <= i; j++) { 7 | System.out.print("*"); 8 | } 9 | System.out.println(); 10 | } 11 | for (int i = 1; i <= 4; i++) { 12 | for (int j = 3; j >= i; j--) { 13 | System.out.print("*"); 14 | } 15 | System.out.println(); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Patterns/star5.java: -------------------------------------------------------------------------------- 1 | package Patterns; 2 | 3 | public class star5 { 4 | public static void main(String[] args) { 5 | for (int i = 1; i <= 4; i++) { 6 | for (int j = 3; j >= i; j--) { 7 | System.out.print(" "); 8 | } 9 | for (int k = 1; k <= i; k++) { 10 | System.out.print("*"); 11 | } 12 | System.out.println(); 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Patterns/star6.java: -------------------------------------------------------------------------------- 1 | package Patterns; 2 | 3 | import java.net.SocketPermission; 4 | 5 | public class star6 { 6 | public static void main(String[] args) { 7 | for (int i = 1; i <= 4; i++) { 8 | for (int j = 1; j <= i; j++) { 9 | System.out.print(" "); 10 | } 11 | for (int k = 4; k >= i; k--) { 12 | System.out.print("*"); 13 | } 14 | System.out.println(); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Patterns/star7.java: -------------------------------------------------------------------------------- 1 | package Patterns; 2 | 3 | public class star7 { 4 | public static void main(String[] args) { 5 | for (int i = 1; i <= 4; i++) { 6 | for (int j = 3; j >= i; j--) { 7 | System.out.print(" "); 8 | } 9 | for (int k = 1; k <= i; k++) { 10 | System.out.print("*"); 11 | } 12 | System.out.println(); 13 | } 14 | for (int i = 1; i <= 4; i++) { 15 | for (int j = 1; j <= i; j++) { 16 | System.out.print(" "); 17 | } 18 | for (int k = 3; k >= i; k--) { 19 | System.out.print("*"); 20 | } 21 | System.out.println(); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Patterns/star8.java: -------------------------------------------------------------------------------- 1 | package Patterns; 2 | 3 | public class star8 { 4 | public static void main(String[] args) { 5 | for (int i = 1; i <= 4; i++) { 6 | for (int j = 1; j <= i; j++) { 7 | System.out.print("*"); 8 | } 9 | System.out.println(); 10 | } 11 | for (int i = 1; i <= 4; i++) { 12 | for (int j = 3; j >= i; j--) { 13 | System.out.print("*"); 14 | } 15 | System.out.println(); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Patterns/star9.java: -------------------------------------------------------------------------------- 1 | package Patterns; 2 | 3 | public class star9 { 4 | public static void main(String[] args) { 5 | for (int i = 1; i <= 4; i++) { 6 | for (int j = 4; j >= i; j--) { 7 | System.out.print(" "); 8 | } 9 | for (int k = 1; k <= i; k++) { 10 | System.out.print(" *"); 11 | } 12 | System.out.println(); 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | hello Everyone, 2 | 3 | This is a Repository for the programs we do everyday on the uncode - Competetive Programming channel (https://www.youtube.com/channel/UCLd1zNPVDBwWBx73ME-K80g) 4 | 5 | This Repo includes all programs related to java Fundamentals taught on Unacademy During the sessions daily. 6 | 7 | You can watch the missed out sessions over here - https://bit.ly/3er2WD5 8 | 9 | Also follow me on unacademy using this link - https://unacademy.com/@unacademy-user-836NVMQPIRXT 10 | 11 | -------------------------------------------------------------------------------- /Revision1/decstar.java: -------------------------------------------------------------------------------- 1 | package Revision1; 2 | 3 | public class decstar { 4 | public static void main(String[] args) { 5 | for (int i = 1; i <= 5; i++) { 6 | for (int j = i; j <= 5; j++) { 7 | System.out.print("*"); 8 | } 9 | System.out.println(); 10 | } 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /Revision1/hillstar.java: -------------------------------------------------------------------------------- 1 | package Revision1; 2 | 3 | public class hillstar { 4 | public static void main(String[] args) { 5 | for (int i = 1; i <= 5; i++) { 6 | for (int j = i; j <= 5; j++) { 7 | System.out.print(" "); 8 | } 9 | for (int k = 1; k <= i; k++) { 10 | System.out.print("*"); 11 | } 12 | for (int l = 2; l <= i; l++) { 13 | System.out.print("*"); 14 | } 15 | System.out.println(); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Revision1/starconcept.java: -------------------------------------------------------------------------------- 1 | package Revision1; 2 | 3 | public class starconcept { 4 | public static void main(String[] args) { 5 | for (int i = 1; i <= 5; i++) { 6 | for (int j = 1; j <= i; j++) { 7 | System.out.print("*"); 8 | } 9 | System.out.println(); 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /While/fact.java: -------------------------------------------------------------------------------- 1 | package While; 2 | 3 | import java.util.Scanner; 4 | 5 | public class fact { 6 | public static void main(String[] args) { 7 | Scanner sc = new Scanner(System.in); 8 | int n = sc.nextInt(); 9 | int i = 1; 10 | int fact = 1; 11 | while (i <= n) { 12 | fact = fact * i; 13 | i++; 14 | } 15 | System.out.println("The factorial of " + n + " is " + fact); 16 | 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /While/fibonacci.java: -------------------------------------------------------------------------------- 1 | package While; 2 | 3 | import java.util.Scanner; 4 | 5 | public class fibonacci { 6 | public static void main(String[] args) { 7 | Scanner sc = new Scanner(System.in); 8 | int count = sc.nextInt(); 9 | int num1 = 0; 10 | int num2 = 1; 11 | int i = 1; 12 | while (i <= count) { 13 | int sumofprev = num1 + num2; 14 | num1 = num2; 15 | num2 = sumofprev; 16 | i++; 17 | } 18 | System.out.print(num1 + " "); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /While/gcd.java: -------------------------------------------------------------------------------- 1 | package While; 2 | 3 | import java.util.Scanner; 4 | 5 | public class gcd { 6 | public static void main(String[] args) { 7 | Scanner sc = new Scanner(System.in); 8 | 9 | int num1 = sc.nextInt(); 10 | int num2 = sc.nextInt(); 11 | 12 | while (num1 != num2) { 13 | if (num1 > num2) { 14 | num1 = num1 - num2; 15 | } else { 16 | num2 = num2 - num1; 17 | } 18 | } 19 | System.out.println("GCD = " + num1); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /While/hcf.java: -------------------------------------------------------------------------------- 1 | package While; 2 | 3 | import java.util.Scanner; 4 | 5 | public class hcf { 6 | public static void main(String[] args) { 7 | Scanner sc = new Scanner(System.in); 8 | int n1 = sc.nextInt(); 9 | int n2 = sc.nextInt(); 10 | int temp; 11 | 12 | while (n2 > 0) { 13 | temp = n2; 14 | n2 = n1 % n2; 15 | n1 = temp; 16 | } 17 | 18 | System.out.println("HCF = " + n1); 19 | 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /While/lcm.java: -------------------------------------------------------------------------------- 1 | package While; 2 | 3 | public class lcm { 4 | public static void main(String[] args) { 5 | int n1 = 15, n2 = 20, lcm; 6 | lcm = (n1 > n2) ? n1 : n2; 7 | 8 | while (true) { 9 | if (lcm % n1 == 0 && lcm % n2 == 0) { 10 | System.out.printf("the lcm of %d and %d is = %d", n1, n2, lcm); 11 | break; 12 | } 13 | ++lcm; 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /While/multi.java: -------------------------------------------------------------------------------- 1 | package While; 2 | 3 | import java.util.Scanner; 4 | 5 | import ForLoops.mult; 6 | 7 | public class multi { 8 | public static void main(String[] args) { 9 | Scanner sc = new Scanner(System.in); 10 | int n = sc.nextInt(); 11 | int i = 1; 12 | int mult = 1; 13 | while (i <= 10) { 14 | mult = n * i; 15 | System.out.println(n + " * " + i + " = " + mult); 16 | i++; 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /While/otn.java: -------------------------------------------------------------------------------- 1 | package While; 2 | 3 | import java.util.Scanner; 4 | 5 | public class otn { 6 | public static void main(String[] args) { 7 | Scanner sc = new Scanner(System.in); 8 | 9 | int n = sc.nextInt(); 10 | int i = 1; 11 | while (i <= n) { 12 | System.out.print(i + " "); 13 | i++; 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /While/positive.java: -------------------------------------------------------------------------------- 1 | package While; 2 | 3 | import java.util.Scanner; 4 | 5 | import loops.whilest; 6 | 7 | public class positive { 8 | public static void main(String[] args) { 9 | Scanner sc = new Scanner(System.in); 10 | int num, sum = 0; 11 | System.out.println("Enter numbers to be added = "); 12 | while (true) { 13 | num = sc.nextInt(); 14 | if (num < 0) { 15 | break; 16 | } 17 | sum = sum + num; 18 | } 19 | System.out.println(sum); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /While/ten.java: -------------------------------------------------------------------------------- 1 | package While; 2 | 3 | public class ten { 4 | public static void main(String[] args) { 5 | int i = 1; 6 | while (i <= 10) { 7 | System.out.print(i + " "); 8 | i++; 9 | } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /helloworld.java: -------------------------------------------------------------------------------- 1 | public class helloworld { 2 | public static void main(String[] args) { 3 | System.out.println("Hello Unacademy!"); 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /loops/dowhilest.java: -------------------------------------------------------------------------------- 1 | package loops; 2 | 3 | import java.util.Scanner; 4 | 5 | public class dowhilest { 6 | public static void main(String[] args) { 7 | Scanner sc = new Scanner(System.in); 8 | 9 | int i = 1; 10 | int n = sc.nextInt(); 11 | 12 | 13 | do{ 14 | System.out.println(i); 15 | i++; 16 | } 17 | while(i<=n); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /loops/whilest.java: -------------------------------------------------------------------------------- 1 | package loops; 2 | 3 | import java.util.Scanner; 4 | 5 | public class whilest { 6 | public static void main(String[] args) { 7 | Scanner sc = new Scanner(System.in); 8 | 9 | int n = sc.nextInt(); 10 | int i = 1; 11 | 12 | 13 | while(i<=n) 14 | { 15 | System.out.println(i); 16 | i++; 17 | } 18 | System.out.println("This is the end of our while loop!"); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /stringsss/sample.java: -------------------------------------------------------------------------------- 1 | package stringsss; 2 | 3 | public class sample { 4 | public static void main(String[] args) { 5 | char[] c = { 'K', 'A', 'B', 'I', 'R' }; 6 | String s = new String(c); 7 | System.out.println(s); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /stringsss/strtodate.java: -------------------------------------------------------------------------------- 1 | package stringsss; 2 | 3 | import java.time.LocalDate; 4 | import java.time.format.DateTimeFormatter; 5 | 6 | public class strtodate { 7 | public static void main(String[] args) { 8 | String string = "2017-07-25"; 9 | LocalDate date = LocalDate.parse(string, DateTimeFormatter.ISO_DATE); 10 | 11 | System.out.println(date); 12 | } 13 | } 14 | --------------------------------------------------------------------------------