Q:

Calculate Sum Of Even Numbers Using Java

0

This Program is used to calculate Sum of Even Numbers using Java.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

/* SUM OF EVEN NUMBER */ 

import java.io.*; 

class ssva18 
{ 
public static void main(String arg[]) 
{ 
long n=0; 
System.out.print("\nSUM OF EVEN NUMBERS IN BETWEEN 1 & 50\n\n\n"); 
for(int i=1;i<=50;i++) 
{ 
if(i%2==0) 
{ 
System.out.print(" "+i); 
n=n+i; 
} 
} 
System.out.println("\n\n\nSUM OF EVEN NUMBERS BETWEEN 1 & 50 IS : "+n); 
System.out.println("\n"); 
} 
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now