Showing posts with label sum. Show all posts
Showing posts with label sum. Show all posts

Saturday, 18 August 2012

Java program to find SUM AND PRODUCT of a given Digit

Java program to find SUM AND PRODUCT of a given Digit :
 Class Sum_Product_ofDigit{
      public static void main(String args[]){
            int number = Integer.parseInt(args[0]);         //taking value as command line argument.
            int temp = number, result=0;
            //Sum of digit
            while(temp>0){
               result = result + temp;
               temp--;
            }
            System.out.println("Sum of Digit for "+number+" is : "+result);
            //product of digit
                        result = 1;
temp = number;
             while(temp > 0){
                 result = result * temp;
                 temp--;
            }
            System.out.println("Product of Digit for "+number+" is : "+result);
   }
}

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


Java program to find sum of all integers greater than 100 and less than 200 that are divisible by 7:
class SumOfSeries{
      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("Sum of the series is : "+result);
   }
}