Page 190 - CA_Blue( J )_Class9
P. 190
10. In a switch statement, the data type of the choice variable should not be …………………..
a. int b. float
c. char d. String
Answers d. all of these
c. char
1. b 2. a 3. c 4. b 5. c 6. b 7. c 8. d 9. a 10. b
B. Fill in the blanks.
1. The switch statement is more efficient than using a series of ………………… statements when comparing a single value
to many possible options.
2. The expression if((a>b) && (c>a)) returns true when ………………… is the greatest number.
3. ………………… statement is mandatory in switch block apart from switch.
4. “if else if” is a ………………… flow of control
5. “switch” block is a ………………… statement.
6. The expression if(a == 0) returns a value of ………………… data type.
7. Some statements within a block are together known as ………………… statement.
8. The expression if(n % 10 == 4) checks whether n is a number ………………… with 4.
9. ………………… flow of control uses Top-Down Appraoch.
10. “if” statement within another “if” statement is known as ………………… if statement.
Answers
1. if-else 2. c 3. case 4. Conditional 5. Multiple Branching
6. boolean 7. Compound 8. ending 9. Normal 10. nested
C. Answer the following questions.
1. Convert the following to Ternary Operator:
if(a>=4 && b==6)
c=a+b;
else
c=a-b;
Ans. c=(a>=4 && b==6)? a+b : a-b;
2. What will be the output of the following code?
char x = 'A';
int m;
m = (x == 'a')? 'A' : 'a';
System.out.println("m = " + m);
Ans. m = 97 [Explanation: Prints the ASCII value of ‘a’]
3. Convert the following to switch case:
int ch,a=7,b=2;
if(ch==1)
System.out.println("Sum " + (a+b));
else
if(ch==2)
System.out.println("Difference " +(a-b));
else
System.out.println("Product " +(a*b));
Ans. int ch,a=7,b=2;
switch(ch)
{
188 Touchpad Computer Applications-IX

