Correct Answer : Get Lastest Questions and Answer : Explanation: A: Output is 2 if Math.random() is greater than 0.5. B: If Math.random() returns a value less equal to 0.5, the code won't throw an exception, it will continue with the doMore() method which will println "4" after which the program will continue with the doStuff() method and will println "3", after that we will be back in main() and the program will print "1".
Question : You have been given below code
public class Two {
public static void main(String[] args) { int day = 1; switch (day) { case "7": System.out.print("Uranus"); case "6": System.out.print("Saturn"); case "1": System.out.print("Mercury"); case "2": System.out.print("Venus"); case "3": System.out.print("Earth"); case "4": System.out.print("Mars"); case "5": System.out.print("Jupiter"); } } }
Which two modifications, made independently, enable the code to compile and run? A. Adding a break statement after each print statement B. Adding a default section within the switch code-block C. Changing the string literals in each case label to integer D. Changing the type of the variable day to String E. Arranging the case labels in ascending order
public static void main(String[] args) { int day = 1; switch (day) { case 7: System.out.print("Uranus"); break; case 6: System.out.print("Saturn"); break; case 1: System.out.print("Mercury"); break; case 2: System.out.print("Venus"); break; case 3: System.out.print("Earth"); break; case 4: System.out.print("Mars"); break; case 5: System.out.print("Jupiter"); break; }
Question : Which three are advantages of the Java exception mechanism?
A. Improves the program structure because the error handling code is separated from the normal program function B. Provides a set of standard exceptions that covers all the possible errors C. Improves the program structure because the programmer can choose where to handle exceptions D. Improves the program structure because exceptions must be handled in the method in which they occurred E. allows the creation of new exceptions that are tailored to the particular program being
Question : Given the code fragment: What is the result? 1. Reading Card Card 2. Compilation fails only at line n1. 3. Compilation fails only at line n2. 4. Compilation fails only at line n3. 5. Compilation fails at both line n2 and line n3.