Given a String variable named line1, write a sequence of statements that use a Scanner to read the first line of a file named "poem" and stores i in line1. (Do not concern yourself with any possible exceptions here-- assume they are handled elsewhere.)

Respuesta :

Answer:

// First create a file object to hold the filename, poem

File file = new File("poem");

// Create a Scanner object to use the file

Scanner input = new Scanner(file);

// Use the input to get the first line in the file

// Store the result in a string variable line1

String line1 = input.nextLine();

Explanation:

The code contains comments that explain the program

Hope this helps!