Computer Applications
Which of the following is true about the default
label in a switch
statement?
Java Conditional Stmts
2 Likes
Answer
It executes if no matching case label is found.
Reason — The default
label in a switch
statement is used as a fallback option. If none of the case
labels match the switch
expression, the default
block executes.
- Including a
default
label is optional in aswitch
statement. - It can appear anywhere within the
switch
block. - The
default
label can appear only once, but its position within theswitch
block is flexible (not restricted to the top).
Answered By
2 Likes
Related Questions
A triangle is said to be an 'Equable Triangle', if the area of the triangle is equal to its perimeter. Write a program to enter three sides of a triangle. Check and print whether the triangle is equable or not.
For example, a right angled triangle with sides 5, 12 and 13 has its area and perimeter both equal to 30.Using the switch-case statement, write a menu driven program to do the following:
(a) To generate and print Letters from A to Z and their Unicode
Letters Unicode A 65 B 66 . . . . . . Z 90 (b) Display the following pattern using iteration (looping) statement:
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5Rewrite the following code using single if statement.
if(code=='g') System.out.println("GREEN"); else if(code=='G') System.out.println("GREEN");
Write a Java program to print name, purchase amount and final payable amount after discount as per given table:
Purchase Amount Discount upto ₹10000/- 15% ₹10000 to ₹ 20000/- 20% Above ₹20000/- 30%