Predict the number of times the loop is executed and output of the following program
segments :
a. for(i = 10; i > 5 ; i--)
System.out.println(i);
b. for(i = 15; i >= 10; i++)
System.out.println(i);
c. for(i = 5;i<= 10; i--)
System.out.println(i);
d. for(i = 15 ; i<= 25 ; i += 2)
System.out.println(i);
e. for(i = 5;i<= 10; i++)
System.out.println(i);
f. int m= 5;
for(n=1 ; n<= m; n++,m--)
System.out.println(n);
System.out.println(m);
g. int x= 2;
while (x< 10)
{
System.ou.println(x);
x+= 3;
}
h. int p= 4;
while(p>0)
{
System.out.println(p);
p-=2;
}
i. int i = 3;
while (i<= 5)
{
System.out.println(i);
i -=2;
}
Answers
Answered by
2
Answer:
first loop 5times
second loop is infinite
third also infinite
fourth loop will execute 6 times
fifth loop 5 times
sixth loop n will be 5times and m will be 1 time
Similar questions
History,
5 months ago
Computer Science,
5 months ago
French,
5 months ago
Physics,
11 months ago
Economy,
1 year ago