How many times will the following code print Welcome to Java
Solution
Ans)
15) D.10
public class MultiQues {
public static void main(String[] args) {
// TODO Auto-generated method stub
int count = 0;
while(count < 10){
System.out.println(\"welcome to java\");
count++;
}
}
}
16) E.45
public class MultiQues {
public static void main(String[] args) {
// TODO Auto-generated method stub
int y = 0;
for(int i=0;i<10;++i){
y+=i;
}
System.out.println(y);
}
}
17) B.10
public class MultiQues {
public static void main(String[] args) {
// TODO Auto-generated method stub
int y = 0;
int i=0;
for(i=0;i<10;++i){
y+=i;
}
System.out.println(i);
}
}
18) B.n
There are n iterations for the given for loop because it is given that i=1 to i <= n so there aren iterations.
19) C.n-1
Here for loop starts from i=1 to i<n so there are up to n-1 iterations only.
