Page 208 - Cs_withBlue_J_C11_Flipbook
P. 208
2. What are compound statements?
Ans. When a group of statements is written within a curly bracket, then it is known as a compound statement.
3. Which statement checks a particular condition?
Ans. If statement checks a particular condition, when the condition is satisfied, then the statement/statements inside under "if" will
be executed. And the course of action will be ignored.
4. What are the different types of conditional Statements?
Ans. The different types of conditional statements are as follows:
• if statement
• if-else statement
• if and only if statement
• if else if statement
• nested if statement
• switch case
5. Write the output.
int a=5, b=2, c=8;
if(c>4)
{
c=a++ + ++b;
System.out.println("The result is "+ c);
}
System.out.println("Outside if block");
Ans. c = 5 + 3
The result is 8
Outside if block
6. What is switch case?
Ans. Switch is a multiple-branch selection statement. It has a variable that is used to select from multiple case statements.
7. Define Fall Through situation? Write an example.
Ans. The moving of control from one case to another case in the absence of a “break” statement is known as Fall Through.
Example,
switch(ch)
{
case 1: System.out.println(5+6);
case 2: System.out.println(5-4);
break;
case 3: System.out.println(5*4);
default: System.out.println(5.0/6.0);
}
8. What is a nested switch case?
Ans. When a switch case is used inside another switch case, then it is known as a nested switch case.
9. What will be the output of the following?
i. int x=5,y=8,z=10;
if(x>y)
{
if(x>z)
{
System.out.println(x);
}
else
{
System.out.println(y);
}
206206 Touchpad Computer Science-XI

