Posts

Concept of recursion using factorial in java

Image
public class P_07_recursion_factorial {      static int factorial(int n)     {                if (n == 1)                  return 1;                else                  return(n * factorial(n-1));          }        public static void main(String[] args) {  System.out.println("Factorial of 5 is: "+factorial(5));  }  } Output  :

Explicit type casting in java

Image
class P_06_explicit {     public static void main(String[] args)     {         double d = 100.04;         long l = (long)d;         int i = (int)l;         System.out.println("Double value "+d);         System.out.println("Long value "+l);         System.out.println("Int value "+i);     } } Output

Implicit type casting in java

Image
class P_06_implicit {     public static void main(String[] args)     {         int i = 100;         long l = i;         float f = l;         System.out.println("Int value "+i);         System.out.println("Long value "+l);         System.out.println("Float value "+f);     } } Output

Handling datatypes in java

Image
class P_05_datatypes {     public static void main(String args[])     {         char a = 'G';         int i=89;         byte b = 4;         short s = 56;         double d = 4.355453532;         float f = 4.7333434f;         System.out.println("char: " + a);         System.out.println("integer: " + i);         System.out.println("byte: " + b);         System.out.println("short: " + s);         System.out.println("float: " + f);         System.out.println("double: " + d);     }  } Output

Fibonacci Series in java

Image
CODE  : a) WHILE LOOP public class P_04_fibb_while_loop { public static void main(String[] args) { int a=1,temp=0,b=0; System.out.println(a); while (a<10) { temp=a+b; b=a; a=temp; System.out.println(temp); temp++; } } } b) DO WHILE LOOP public class P_04_do_fibb_while_loop { public static void main(String[] args) { int a=1,temp=0,b=0; System.out.println(a); do{ temp=a+b; b=a; a=temp; System.out.println(temp); temp++; }while (a<10); } } c) FOR LOOP public class P_04_fibb_for_loop { public static void main(String[] args) { int a=1,temp=0,b=0; System.out.println(a); for(;a<10;temp++) { temp=a+b; b=a; a=temp; System.out.println(temp); } } } Output  :

To print days of week using switch case in java

Image
CODE  : class P_03_print_day_switch_case_part3 { public static void main(String[] args) { int a=1; switch (a) { case 0: System.out.println("Today is Monday"); break; case 1: System.out.println("Today is Tuesday"); break; case 2: System.out.println("Today is Wednesday"); break; case 3: System.out.println("Today is Thursday"); break; case 4: System.out.println("Today is Friday"); break; case 5: System.out.println("Today is Saturday"); break; case 6: System.out.println("Today is Sunday"); break; default: System.out.println("You are doomed"); } } } Output  :