Consider the code that follows. What does it do?
String value = "2";boolean tryAgain = true;
while (tryAgain == true)
{
try
{
int num = Integer.parseInt(value);
tryAgain = false;
}
System.out.println("Valid integer");
catch(NumberFormatException nfe)
{
System.out.println("Invalid integer");
System.out.print("Enter an integer");
value = sc.next
}
}
a. It prints "Invalid integer" to the console.
b. The code compiles but causes a runtime error.
c. The code doesn't compile.
d. It prints "Valid integer" to the console.
Answer: The code doesn't compile.
Output example:
Exception in thread "main" java.util.InputMismatchException
at java.util.Scanner.throwFor(Scanner.java:818)
at java.util.Scanner.next(Scanner.java:1420)
at java.util.Scanner.nextDouble(Scanner.java:2324)
at FutureValueApp.main(FutureValueApp.java:17)
Learn More :
Mobile App
- What is the most common file type of media supported for audio playback on the Android?
- What is the first GridView control in a project named by default?
- What is the TextView property for backgrounds?
- What invokes a scheduled Timer?
- What does the splash screen provide time for Android to do?
- What category of the Palette does the control GridView sit in?
- What can be described as the series of actions from the beginning of an Activity to its end?
- Using controls such as the GridView and Spinner, what binds specific types of data and displays that data in a particular layout?
- On an Android, what are 1000 milliseconds equivalent to in seconds?
- Each of the following is a common state for the MediaPlayer class except for which one?
- What is printed to the console after the code that follows is executed?
- What happens when the code that follows is executed?
- To use the binarySearch method of the Arrays class on an array of ints, you must first
- The length of the array that follows is int[] grades = new int[4];
- The array that follows is an array of double[] grades = new double[3];
- How many rows are in the array that follows? Rental[][] transactions = new Rental[7][3];
- What is the length of the bestTimes array?
- An enhanced for loop can only be used
- Which of the following is not a reason to create a package?
- Which of the following is a valid Javadoc comment?
- Which of the following is a benefit of using Javadoc comments?
- Where must you code the Javadoc comment for a method?
- To include a class in a package, you
- In what type of file is Javadoc documentation stored?
- A subclass inherits