Computer Applications
How many times the given loop is executed? Give the output of the same.
for(k=10;k<=20;k+=4)
{
System.out.println(k);
if(k%3==0) continue;
}
Java Iterative Stmts
2 Likes
Answer
The loop exectes 3 times.
Output
10
14
18
Explanation
The loop starts from k = 10 and runs as long as k <= 20, increasing k by 4 each time. So, the values of k will be: 10, 14, and 18. When k becomes 22, the condition k <= 20 becomes false, so the loop stops. Hence, the loop runs 3 times.
Answered By
1 Like
Related Questions
Give the output of the following program segment:
for(r=1;r<=3;r++) { for(c=1;c<r;c++) { System.out.println(r); } }Give the output of the following program segment:
void encode() { String s= "DICe"; char ch; for(i=0;i<4;i++) { ch=s.charAt(i); if("AEIOUaeiou".indexOf(ch)>=0) System.out.println("@"); else System.out.println(ch); }Name the following:
(a) What is the main condition to perform binary search on an array?
(b) A sort method in which consecutive elements are NOT compared.
Answer the following:
(a) Scanner class method to accept a character.
(b) Jump statement which stops the execution of a construct.