Give the output of the given program segments:- [2 X 2 =4]
. int x=10, s=0;
while(x>0)
{
System.out.print(x+” \t”);
s = s + x;
x = x - 2;
}
System.out.println();
System.out.println(s);
Answers
Answered by
83
The output:
10 8 6 4 2
30
Explanation:
The value of x is initialized x at 10 and it's printed very time the loop runs with a tab, also it's value reduces with the loop till it is greater than 0.
s is initialized at 0 and the varying value of x with a loop is added to s and it's printed at the end with x before it.
Similar questions
Hindi,
2 months ago
Social Sciences,
2 months ago
History,
10 months ago
Social Sciences,
10 months ago