Posts

Automatic Type Casting

 package type_casting; public class Type_Casting_narrowing { public static void main(String[] args) { double my_double = 2.8965; System.out.println(my_double); int my_int = (int)my_double; System.out.println(my_int); } }

Variable

 package data_types; public class Data_Types { public static void main(String[] args) { byte x = 2; System.out.println(x); int age = 10; System.out.println(age); float rate_of_intrest = 2.3f; System.out.println(rate_of_intrest); double rate = 3.1428571; System.out.println(rate); boolean isThisSeriesofcodes = false; System.out.println(isThisSeriesofcodes); char myCharacter = '@'; System.out.println(myCharacter); } }

Average Marks Of Students

 package arrays; import java.util.Scanner; public class AverageMarksOfStudents { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.print("Enter the number ofstudents : "); int n = sc.nextInt(); int[] marks = new int [n]; for(int i = 0; i<n ; i++) { marks [i] = sc.nextInt(); } int averageMarks = 0; for(int i = 0; i<n ; i++) { averageMarks += marks[i]; } averageMarks /= n; System.out.println("The average marks of students are "+ averageMarks); } }

Introduction To Array

 package arrays; import java.util.Scanner; public class ArrayIntro { public static void main(String[] args) { /* int[] marks; marks = new int[5]; */ //int marks[] = new int [5]; //ALL ARE SAME int[] age = {2,4,8,16,32}; double[] percentage = {1.0,3.14,4.6,78}; Scanner sc = new Scanner(System.in); while(6>age.length) { int n = sc.nextInt(); System.out.println(age[n-1]); }}}

Find Palindrome Number

 package whileLoops; import java.util.Scanner; public class PalindromeNumber { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int temp = n; int reversedNumber = 0; while(temp>0) { int lastDigit = temp % 10; reversedNumber = reversedNumber * 10 + lastDigit; temp /= 10; } if (reversedNumber == n) { System.out.println(n+ "  is palindrome"); } else { System.out.println(n + " is not a palindrome"); } } }

Sum of Digits

 package whileLoops; import java.util.Scanner;  public class SumOfDigits { public static void main(String[] args) { Scanner sc = new  Scanner(System.in); int n = sc.nextInt(); int temp = n; int sum = 0; while(temp >0) { int lastDigit = temp%10; temp /= 10; sum += lastDigit; System.out.println(" Last Digit " + lastDigit + " temp " + temp + " Sum " + sum); } System.out.println("The sum of all digit of " + n + " is " + sum); } }

Pattern 4

 package nestedForLoop; import java.util.Scanner; public class Pattern4 {   public static void main(String[] agrs) { Scanner sc = new Scanner(System.in); int a = sc.nextInt(); for(int i = 1;i<=a ;i++) { for(int j = 1;j<=a-i ; j++) { System.out.print("  "); } for(int j = 1;j<=i ;j++) { System.out.print("x  "); } System.out.println(); } } }