Question: public static void main(String[] args) throws FileNotFoundException { Scanner scan = new Scanner(new File(srclist.dat)); while (scan.hasNextLine()) { String line = scan.nextLine(); String[] num = line.split(

 public static void main(String[] args) throws FileNotFoundException { Scanner scan =

public static void main(String[] args) throws FileNotFoundException { Scanner scan = new Scanner(new File("src\\list.dat")); while (scan.hasNextLine()) { String line = scan.nextLine(); String[] num = line.split(" "); int[] arr = new int[Integer.parseInt(num[0])]; for (int i = 1; i

I have this piece of code. Now all I need to do is skip the line that has first integer (list size) 0 or negative integer and list all the used integers.

Write a JAVA application that reads the integers line by line and prints its sum from a file.dat file.dat 5 150 6-1 2 110 0 -1 30 15 5 The first integer is list size. If it is n, then it has n elements. . If the list size is 0 or negative integers, ignore the line and skip to next line The above example should generate following output: Integers Used 1506-1 1 10 015 5 Sum 20

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!