Find the Output - While Loop based
/ Java Theory QuestionsCode Sample 1
int x = 1, i = 2;
while(++i <= 5)
{
x *= i;
}
System.out.println(x);
output
60
Code Sample 2
int i = 1;
int d = 5;
while(i <= 5)
{
d = d * 2;
System.out.println(d);
i++;
}
output
10
20
40
80
160
Code Sample 3
int m = 5, n = 10;
while (n >= 1)
{
System.out.println(m * n);
n--;
}
output
50
45
40
35
30
25
20
15
10
5
Code Sample 4
int x = 1, s = 0;
while (x <= 7)
{
s += x;
x += 2;
}
System.out.println(s);
output
16
Code Sample 5
int x = 5;
int y = 75;
while (x <= y)
{
y = y/x;
System.out.println(y);
}
output
15
3
Code Sample 6
int x = 10, c = 20;
while(c >= 10)
{
x++;
c = c - 2;
System.out.println(c);
}
output
18
16
14
12
10
8
Code Sample 7
int p = 200;
while(true)
{
if(p < 100)
break;
p = p - 20;
}
System.out.println(p);
output
80
Code Sample 8
int x = 0;
while(x++ < 20)
{
if(x % 2 == 0)
System.out.println("Simply");
else if (x == 9)
break;
else
continue;
}
output
Simply
Simply
Simply
Simply