write a program in java to find the sum of first ten even numbers.
Answers
Answered by
22
- Java Program :
- class sum_even. { public static void main() { int s=0,i,c=0; for(i=1;;i++) { if(i%2==0) { s=s+i; c=c+1; } if(c==10) break; } System.out.print("Sum : "+s); } } Output :
- Sum : 110. Note : Use the calculator and the notepad provided, at the top, to dry run the program.
- hope it helps you..
Answered by
2
ANSWER::
To print the sum of the first ten even numbers in Java
Java Program :
class sum_even. { public static void main() { int s=0,i,c=0; for(i=1;;i++) { if(i%2==0) { s=s+i; c=c+1; } if(c==10) break; } System.out.print("Sum : "+s); ...
class sum_even. { public static void main() { int s=0,i,c=0; for(i=1;;i++) { if(i%2==0) { s=s+i; c=c+1; } if(c==10) break; } System.out.print("Sum : "+s); ...Sum : 110.
Note : Use the calculator and the notepad provided, at the top, to dry run the program.
Similar questions