Posts

Showing posts from January, 2015

Program to find sum of all integers greater than 100 and less than 200 that are divisible by 7.

Source code class SumOfDigit{       public static void main(String args[]){       int result=0;       for(int i=100;i<=200;i++){            if(i%7==0)               result+=i;       }       System.out.println("Output of Program is : "+result);    } }

Program to find Fibonacci series of a given no.

Source code     class Fibonacci{       public static void main(String args[]){           int num = Integer.parseInt(args[0]);                        //taking no. as command line argument.           System.out.println("*****Fibonacci Series*****");           int f1, f2=0, f3=1;           for(int i=1;i<=num;i++){              System.out.print(" "+f3+" ");              f1 = f2;              f2 = f3;              f3 = f1 + f2;           }    } }

Program to Reverse a given no.

Source code class Reverse{       public static void main(String args[]){           int num = Integer.parseInt(args[0]);               //take argument as command line           int remainder, result=0;           while(num>0){               remainder = num%10;               result = result * 10 + remainder;               num = num/10;          }          System.out.println("Reverse number is : "+result);     } }

Program to Find Factorial of Given no.

Source code   class Factorial{       public static void main(String args[]){           int num = Integer.parseInt(args[0]);                 //take argument as command line           int result = 1;           while(num>0){                 result = result * num;                 num--;           }           System.out.println("Factorial of Given no. is : "+result);    } }  

Program to find SUM AND PRODUCT of a given Digit.

Source code class Sum_Product_ofDigit{       public static void main(String args[]){             int num = Integer.parseInt(args[0]);         //taking value as command line argument.             int temp = num,result=0;             //Logic for sum of digit             while(temp>0){                result = result + temp;                temp--;             }             System.out.println("Sum of Digit for "+num+" is : "+result);             //Logic for product of digit             temp = num;             result = 1;             while(temp > 0){                  result = result * temp;                  temp--;             }             System.ou

Program to generate 5 Random nos. between 1 to 100.

Source code   class RandomDemo{       public static void main(String args[]){           for(int i=1;i<=5;i++){               System.out.println((int)(Math.random()*100));           }     } }

Minimum of 2 nos. using conditional operator

Source code class Minof2{       public static void main(String args[]){       //taking value as command line argument.       //Converting String format to Integer value       int i = Integer.parseInt(args[0]);       int j = Integer.parseInt(args[1]);       int result = (i<j)?i:j;       System.out.println(result+" is a minimum value");   } }

Maximum of two numbers

Source Code class Maxof2{   public static void main(String args[]){       //taking value as command line argument.       //Converting String format to Integer value       int i = Integer.parseInt(args[0]);       int j = Integer.parseInt(args[1]);       if(i > j)           System.out.println(i+" is greater than "+j);       else           System.out.println(j+" is greater than "+i);   }