Saturday, October 12, 2019

CBSE Grade 12 Java Find the output questions and answers-2014

Tags












Write the value of sum1 after execution of the following WHILE
loop :


int i = 1,
sum1 = 0;
while (i<10){
sum1 =sum1+ i;
i =i+2;}






Write the value of sum1 after execution of the following WHILE loop


Compiled code for "Write the value of sum1 after execution of the following WHILE loop"


Working of the code is given below:




Given int i=1 ; and sum1=0
From codesum1= sum1+iValue of i-at this point
= 0 +1 = 1Due to i=i+21+2=3
Now i=3which is < 10= 1 +3 = 4Due to i=i+23+2=5
Now i=5which is < 10= 4+5 = 9Due to i=i+25+2=7
Now i=7which is < 10= 9+7 = 16Due to i=i+27+2=9
Now i=9which is < 10= 16+9 = 25Due to i=i+29+2=11
Now i=11which is not < 10 so the code ends.Output =25


Welcome to our educational Website!