Given the code fragment:
public static void main (String [ ] args) throws IOException {
BufferedReader br = new BufferedReader (new InputStremReader (System.in));
System.out.print (“Enter GDP: “);
//line 1
}
Which code fragment, when inserted at line 1, enables the code to read the GDP from the user?
A.
int GDP = Integer.parseInt (br.readline());
B.
int GDP = br.read();
C.
int GDP = br.nextInt();
D.
int GDP = Integer.parseInt (br.next());
A
B.
int GDP = br.read();
Enter GDP: 5555 BUILD SUCCESSFUL
B IS THE RIGHT ANSWER
A. is correct
A
A also correct.
A is correct because you can use only integers for integers.
B.
Answer A causes compiler error – Cannot resolve method ‘readline()’