Computer Science, asked by himanshupassey26, 11 months ago

C++ question....

What will be the output of the program ? Class test{public static void main(string[] args){int x=0; int y =0; int sum =0; for (int z=1; z<20; z++) {sum+=z;}system.out.println(sum);}}

Answers

Answered by anupama777vidya
1

Answer:

210

Hope it helps you

Answered by suskumari135
1

Output of the program

Explanation:

The program will iterates from number 1 to the number 20 specified, adding all numbers and save result to variable sum and print it.

Java Program to calculate the sum using for loop

public class Main {

   public static void main(String[] args) {

       int x = 0, sum = 0;

       for(int z = 1; z <= 20; z++)

       {

           sum += z;

       }

       System.out.println("Sum = " + sum);

   }

}

Output:

Sum = 210

The program is attached below

Attachments:
Similar questions