int v2 = input.nextInt();
String line = input.nextLine();
a. After the last statement is executed, v1 is 34.
b. The program has a runtime error because 34.3 is not an integer.
c. After the last statement is executed, line contains characters ‘7’, ‘8’, ‘9’, ‘\n’.
d. After the last statement is executed, line contains characters ‘7’, ‘8’, ‘9’.
#
44. Suppose you enter 34.3 57.8 789, then press the ENTER key. Analyze the following code.
Scanner input = new Scanner(System.in);
double v1 = input.nextDouble();
double v2 = input.nextDouble();
String line = input.nextLine();
a. After the last statement is executed, line contains characters ‘7’, ‘8’, ‘9’.
b. After the last statement is executed, line contains characters ‘7’, ‘8’, ‘9’, ‘\n’.
c. After the last statement is executed, line contains characters ‘ ‘, ‘7’, ‘8’, ‘9’, ‘\n’.
d. After the last statement is executed, line contains characters ‘ ‘, ‘7’, ‘8’, ‘9’.
#
45. Suppose you enter 34.3, the ENTER key, 57.8, the ENTER key. Analyze the following code.
Line 1 Scanner input = new Scanner(System.in);
Line 2 double v1 = input.nextDouble();
Line 3 double v2 = input.nextDouble();
Line 4 String line = input.nextLine();
a. After line 2 is executed, v1 is 34.3.
b. After line 3 is executed, v2 is 57.8.
c. After line 4 is executed, line contains an empty string.
d. After line 4 is executed, line is null.
e. After line 4 is executed, line contains character “\n”.
#
46. Suppose you enter 34.3, the ENTER key, 57.8, the ENTER key, abc, the Enter key. Analyze the following code.
Line 1 Scanner input = new Scanner(System.in);
Line 2 double v1 = input.nextDouble();
Line 3 double v2 = input.nextDouble();
Line 4 String line = input.nextLine();
a. After line 2 is executed, v1 is 34.3.
b. After line 3 is executed, v2 is 57.8.
c. After line 4 is executed, line contains an empty string.
d. After line 4 is executed, line is null.
e. After line 4 is executed, line contains character “abc”.
#
Section 12.12 Reading Data from the Web
48. To create an InputStream to read from a file on a Web server, you use the method in the URL