1.

Write a program in java to find the sum of first ten even numbers.​

Answer»

>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..


    Discussion

    No Comment Found