
how to print the sum of even number from 1 to 100 using for loops?
Thanks.

Java print the sum of even number from 1 to 100
class Loops{
public static void main(String[] args){
int sum=0;
for(int i=1;i<=100;i++){
if(i%2==0){
System.out.println(i);
sum+=i;
}
}
System.out.println("Sum of even numbers: "+sum);
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.