Which code fragment, when inserted at line 1, enables the code to read the GDP from the user?

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());

Download Printable PDF. VALID exam to help you PASS.

5 thoughts on “Which code fragment, when inserted at line 1, enables the code to read the GDP from the user?

  1. Not only you need the see the use of ioexception as well, this code cannot manage by its own in the current state.

  2. Answer is A:
    Option A, after reading a string from the standard input stream, converts to an integer store.

    Option B, the read method of the BufferedReader object reads a character, and then returns the value of the character, not the desired result.

    Option C, BufferedReader object does not have nextInt method, it will compile error. Scanner items only.

    Option D, BufferedReader object without the next method, will compile errors. Scanner items only.

Leave a Reply

Your email address will not be published. Required fields are marked *


The reCAPTCHA verification period has expired. Please reload the page.