Question: In the code below, we compute the sum of integers in a file, first reading them as strings and then parsing the strings. Rearrange the

In the code below, we compute the sum of integers in a file, first reading them as strings and then parsing the strings. Rearrange the following lines of code so that the input file is closed even if the Integer.parseInt method throws an exception. Place as many statements as possible inside the try block.
How to use this tool
Unused }
while (in. hasNext())
{
try Scanner in = new Scanner new File("numbers.txt"))){
int total =0;
total = total + input;
System.out.println(total);
}
int input = Integer. parseInt(in. next());
Sum.java
Load default template...
import java.util. Scanner;
import
java.io. File;
import
java.io. FileNotFoundException;
public class Sum
{
public static void main (String [] args)
throws FileNotFoundException
{
}
}
}
 In the code below, we compute the sum of integers in

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!