Monday, 2 November 2015

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


Write a program to find sum of all integers greater than 1 and less than 100 that are divisible by 7.

Sample Program:-

 /**  
  * @author Dixit  
  *   
  */  
 public class SumOfDigit {  
      /**  
       * @param args  
       */  
      public static void main(String[] args) {  
           int result = 0;  
           for (int i = 1; i <= 100; i++) {  
                if (i % 7 == 0)  
                     result += i;  
           }  
           System.out.println("Output of Program is : " + result);  
      }  
 }  

 Output  
 Output of Program is : 735  


Enjoy Programming.

No comments:

Post a Comment