Analyze how many times the following loop gets executed and write the output:
int k=500, m=10;
while (true)
{
System.out.println (k);
if(k%m==0)
{
k=k/m;
continue;
}
else if(k==5)
break;
}
(3) int x;
for (x=1; ; x++)
{
System.out.println (x);
if(x%5==0)
break;
}
(4) int m;
for(m=10; m>0 & m<=30; m+=10);
System.out.println ("m="+m);
(5) for (int i=1;i<=3;i++)
{
for (int j=1; j<=3; j++)
{
System.out.print(j);
if(j%2==0)
break;
}
System.out.println ();
Answers
Answered by
1
Answer:
The first loop will executes 3 times.
OUTPUT:
500
50
5
(3) :
Loop executes 5 times.
OUTPUT:
1
2
3
4
5
(4) :
Loop executes 3 times.
OUTPUT:
m=10
m=20
m=30
(5) :
The outer loop executes 3 times.
The inner loop executes 3 times for every outer loop execution.
OUTPUT:
12
12
12
Similar questions
Math,
5 months ago
English,
5 months ago
Hindi,
5 months ago
India Languages,
9 months ago
Math,
1 year ago