Page 210 - Cs_withBlue_J_C11_Flipbook
P. 210
Ans. if(m==0){
x= x+2;
System.out.println("X=" +x);
}
else if(m==1){
x= x+4;
System.out.println("X=" +x);
}
if(m==2){
x= x+6;
System.out.println("X=" +x);
}
11. Convert the following from for to while loop and write the output:
int a,b;
for(a = 5,b = 2; a>b ; a-- , b++)
{
System.out.println(a+b);
}
Ans. int a=5,b=2;
while(a>b)
{
System.out.println(a+b);
a--;
b++;
}
Output :
7
7
12. Find the error:
int i=5;
while(i>=15)
{
System.out.println(i)
i=i-2;
}
Ans. The loop will not execute since starting value of i is less than the condition.
Unsolved Questions
A. Tick ( ) the correct option:
1. Which of the following methods finds the highest value of x and y in Java?
a. Math.max(x,y) b. Math.high(x,y)
c. Max.Math(x,y) d. High.Math(x,y)
2. Which of the following data types cannot be used in a switch statement?
a. boolean b. int
c. char d. string
3. The code given below is an example of:
for(i=10; i>=1; i++)
{
System.out.println(i);
}
a. Delay loop b. Empty loop
c. Infinite loop d. None of these
208208 Touchpad Computer Science-XI

