├── README.md ├── sum of natural number.java ├── Ascii.java ├── find factorial.java ├── vowel or non vowel.java ├── quotientremainder.java ├── Largest of three.java ├── Find gcd.java ├── reverse_number.java ├── check leap year.java ├── Trainglearea.java ├── Perimeter.java ├── si.java ├── Grading.java ├── Linearsearch.java └── Binary search.java /README.md: -------------------------------------------------------------------------------- 1 | # starting-java -------------------------------------------------------------------------------- /sum of natural number.java: -------------------------------------------------------------------------------- 1 | //code to get sum 2 | public class sumnatural{ 3 | public static void main(string[] args){ 4 | int num=100,sum=0; 5 | //find sum of natural 6 | for(int i=1;i<=num;++i) 7 | { 8 | sum+=i; 9 | } 10 | System.out.println(sum) 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Ascii.java: -------------------------------------------------------------------------------- 1 | //using a 2 | //find ascii value 3 | public class AsciiValue{ 4 | public static void main(String[] args){ 5 | //change alphabet to check other values 6 | char ch='a'; 7 | int asccii=ch; 8 | int castAscii=(int) ch; 9 | //get output 10 | System.out.println("the ascii is"+ch+"is"+ascii); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /find factorial.java: -------------------------------------------------------------------------------- 1 | //find factorial 2 | public class factorial{ 3 | public static void main(string[] args){ 4 | int num=10; 5 | long factorial=1; 6 | //used for loop 7 | for(int i=1; i<=num; ++i) 8 | { 9 | factorial*=i; 10 | } 11 | System.out.println("factorial of %d=%d",num,factorial) 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /vowel or non vowel.java: -------------------------------------------------------------------------------- 1 | //find the vowel and constent 2 | public class vowelquoinent{ 3 | public static voi main(String[] args){ 4 | //use your own character 5 | char ch='i'; 6 | if(ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u') 7 | System.out.println(ch +"is vowel"); 8 | else 9 | System.out.println(ch +"is not vowel"); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /quotientremainder.java: -------------------------------------------------------------------------------- 1 | //code to get quotient remainder 2 | public class quotientremainder{ 3 | public static void main(String[] args){ 4 | int dividend=25,divisor=4; 5 | int quotient=dividend/divisor;; 6 | int remainder=dividend % divisor; 7 | System.out.println("quotient="+quotient) 8 | System.out.println("remainder is"+remainder) 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Largest of three.java: -------------------------------------------------------------------------------- 1 | //import java 2 | //fin 3 | public class Largest{ 4 | public static void main(string[] args){ 5 | double n1=4.5,n2=0.9,n3=9.0; 6 | if(n1>=n2 && n1>=n3) 7 | System.out.println(n1+"is largest"); 8 | else if(n2>=n1 && n2>=n3) 9 | System.out.println(n2+"is largest"); 10 | else{ 11 | System.out.println(n3+"is largest"); 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Find gcd.java: -------------------------------------------------------------------------------- 1 | //find gcd 2 | class main{ 3 | public static void main(string[] args){ 4 | //change value according to you 5 | int n1=81,n2=153; 6 | int gcd=1; 7 | //used for loop 8 | for(int i=1;i<=n1 && i<=n2;++i){ 9 | //used conditional statement 10 | if(n1 % i==0 && n2%i==0) 11 | gcd=i; 12 | } 13 | //get output 14 | System.out.println("GCD of"+n1+"and"+n2+"is"+gcd); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /reverse_number.java: -------------------------------------------------------------------------------- 1 | //code to get reverse of number 2 | class Main{ 3 | public static void main(string[] args){ 4 | //use your own value of original numbers 5 | int num=1234,reversed=0; 6 | System.out.println("orginal num"+num); 7 | //using while loop 8 | while(num!=0){ 9 | int digit=num%10; 10 | reversed=reversed*10+digit; 11 | num/=10; 12 | } 13 | System.out.println("reversed number:"+reversed); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /check leap year.java: -------------------------------------------------------------------------------- 1 | //implemented in Java 2 | //checking Leap year or non leap year 3 | public class main{ 4 | public static void main(string[] args){ 5 | int year=100; 6 | boolean leap=false; 7 | if(year%4==0){ 8 | if(year%100=0){ 9 | if(year%400==0){ 10 | leap =true; 11 | else{ 12 | leap=false; 13 | } 14 | } 15 | } 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Trainglearea.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | class Traingle{ 3 | public static void main(string[] args){ 4 | Scanner input=new Scanner(system.in); 5 | System.out.println("welcome to area calculator\n"); 6 | System.out.print("please enter your base in cms"); 7 | double.base=input.nextDouble(); 8 | System.out.print("enter your height"); 9 | double height=input.nextDouble(); 10 | 11 | double area=(base*height)/2; 12 | 13 | System.out.println(area) 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Perimeter.java: -------------------------------------------------------------------------------- 1 | //find perimeter 2 | //import java.util.sca 3 | import java.util.Scanner; 4 | class Perimeter{ 5 | public static void main(string[] args){ 6 | //input data here 7 | Scanner input=new Scanner(System.in); 8 | System.out.println("welcome to perimeter calculator"); 9 | System.out.print("please enter all 4 sides in cms"); 10 | double a=input.nextDouble(); 11 | double b=input.nextDouble(); 12 | double c=input.nextDouble(); 13 | double d=input.nextDouble(); 14 | 15 | double perimeter=a+b+c+d; 16 | System.out.println(perimeter); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /si.java: -------------------------------------------------------------------------------- 1 | //find simple interest 2 | import java.util.Scanner; 3 | class si{ 4 | public static void main(string[] args){ 5 | //input value here 6 | Scanner input=new Scanner(system.in); 7 | System.out.println("welcome to si calculator"); 8 | System.out.print("enter your principle"); 9 | int principle=input.nextInt(); 10 | System.out.print("enter your rate"); 11 | Float rate=input.nextFloat(); 12 | System.out.print("enter time"); 13 | int time=input.nextInt(); 14 | 15 | float intreset=(principle*rate*years)/100; 16 | System.out.println(intreset) 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Grading.java: -------------------------------------------------------------------------------- 1 | //import java.util.scanner 2 | import java.util.Scanner; 3 | class Grading{ 4 | public static void main(string[] args){ 5 | //enter input value 6 | Scanner input = new Scanner(system.in); 7 | System.out.println("welcome\n"); 8 | System.out.print("please enter your percentage"); 9 | float percentage=input.nextFloat(); 10 | //using conditional statements 11 | 12 | if(percentage>=90){ 13 | System.out.println("A"); 14 | } else if(percentage>=75){ 15 | System.out.println("B"); 16 | } else if(percentage>=60){ 17 | System.out.println("C") 18 | } 19 | else{ 20 | System.out.println("D") 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Linearsearch.java: -------------------------------------------------------------------------------- 1 | //Linear search implementation in java 2 | public class LinearSearch { 3 | 4 | public static int linearSearch(int[] arr, int target) { 5 | for (int i = 0; i < arr.length; i++) { 6 | if (arr[i] == target) { 7 | return i; 8 | } 9 | } 10 | return -1; // Return -1 if target is not found 11 | } 12 | 13 | public static void main(String[] args) { 14 | int[] numbers = {5, 12, 3, 9, 1, 7}; 15 | int targetValue = 9; 16 | 17 | int result = linearSearch(numbers, targetValue); 18 | 19 | if (result != -1) { 20 | System.out.println("Element " + targetValue + " found at index: " + result); 21 | } else { 22 | System.out.println("Element " + targetValue + " not found in the array."); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Binary search.java: -------------------------------------------------------------------------------- 1 | //Binary search in java using recursion 2 | //using recursive approach 3 | //implemented Binary search in java prog 4 | class BinarySearch { 5 | int binarySearch(int array[], int x, int low, int high) { 6 | 7 | // Repeat until the pointers low and high meet each other 8 | while (low <= high) { 9 | //getting mid 10 | int mid = low + (high - low) / 2; 11 | 12 | //checking mid 13 | if (x == array[mid]) 14 | return mid; 15 | 16 | if (x > array[mid]) 17 | low = mid + 1; 18 | 19 | else 20 | high = mid - 1; 21 | } 22 | 23 | return -1; 24 | } 25 | 26 | public static void main(String args[]) { 27 | BinarySearch ob = new BinarySearch(); 28 | int array[] = { 3, 4, 5, 6, 7, 8, 9 }; 29 | int n = array.length; 30 | int x = 4; 31 | int result = ob.binarySearch(array, x, 0, n - 1); 32 | if (result == -1) 33 | System.out.println("Not found"); 34 | else 35 | System.out.println("Element found at index " + result); 36 | } 37 | } 38 | --------------------------------------------------------------------------------