Answer: Option AExplanation:Switch statements are based on integer expressions and since both bytes and chars can implicitly be widened to an integer, these can also be used. Also shorts can be used. Short and Long are wrapper classes and reference types can not be used as variables.
Java
Topic: Flowcontrol
Which two are acceptable types for x?
switch(x) {
default:
System.out.println("Hello"); }
byte
long
char
float
Short
Long
A. 1 and 3
B. 2 and 4
C. 3 and 5
D. 4 and 6
Browse random answers:
Find the output of this program public void foo( boolean a, boolean b){ if( a ){ System.out.println("A"); /* Line 5 */ } else if(a && b) /* Line 7 */ {System.out.println( "A && B");} else /* Line 11 */ { if ( !b ){ System.out.println( "notB") ; } else {System.out.println( "ELSE" ) ;} } }
Which two are acceptable types for x? switch(x) { default: System.out.println("Hello"); } byte long char float Short Long A. 1 and 3 B. 2 and 4 C. 3 and 5 D. 4 and 6
Which of the below statement is true? public void test(int x) { int odd = 1; if(odd) /* Line 4 */ { System.out.println("odd"); } else { System.out.println("even"); } } A. Compilation fails. B. "odd" will always be output. C. "even" will always be output. D. "odd" will be output for odd values of x, and "even" for even values.
Which of the below statement is true? public class While { public void loop(){ int x= 0; while ( 1 ) /* Line 6 */ { System.out.print("x plus one is " + (x + 1)); /* Line 8 */ } } } A. There is a syntax error on line 1. B. There are syntax errors on lines 1 and 6. C.There are syntax errors on lines 1, 6, and 8. D. There is a syntax error on line 6
How do you write an infinite loop using the for statement?
How do you write an infinite loop using the while statement?
Consider the following code snippet.if (aNumber >= 0) if (aNumber == 0) System.out.println("first string");else System.out.println("second string");System.out.println("third string"); Exercise: What output do you think the code will produce if aNumber is 3?
Write a test program containing the previous code snippet; make aNumber 3. What is the output of the program? Is it what you predicted? Explain why the output is what it is. In other words, what is the control flow for the code snippet?
Explain the If-else Statement ?
Explain Switch Case Statement?
Write switch case example?
Write syntax of while?
Write example of while loop?
Write syntax of do while?
Write example of do while?
Write explain Syntax of for loop?
Write example of for loop?