Getting this error when I run my code, note that it finds a problem at line 37, but I cannot figure out what it is. Running the first iteration of the scanner method (for input 1) worked fine, and yielded the proper output, but none of the consecutive ones have, and I've been stuck on that issue. Code is below:
import java.io.FileNotFoundException;
import java.io.File;
import java.util.Scanner;
public class Assignment2 {
public static void main(String[] args) {
int largest= 0;
int largestEven = 0;
int countOfAllPositive = 0;
int sumOfAll = 0;
try {
Scanner input1 = new Scanner(new File("input1.txt"));
while (input1.hasNextInt()) {
if (input1.nextInt() == 0)
{ break;
} else if (input1.nextInt() < largest)
{ largest = input1.nextInt();
} else if (input1.nextInt() > 0)
{ largestEven += input1.nextInt();
} else if (input1.nextInt() % 2 == 0)
{ countOfAllPositive += input1.nextInt();
} else if (input1.nextInt() < 0)
{ sumOfAll++;
}
}
Scanner input2 = new Scanner(new File("input2.txt"));
while (input2.hasNextInt()) {
if (input2.nextInt() == 0)
{ break;
} else if (input2.nextInt() < largest)
{ largest = input2.nextInt();
} else if (input2.nextInt() > 0)
{ largestEven += input2.nextInt();
} else if (input2.nextInt() % 2 == 0)
{ countOfAllPositive += input2.nextInt();
} else if (input2.nextInt() < 0)
{ sumOfAll++;
}
}
Scanner input3 = new Scanner(new File("input3.txt"));
while (input3.hasNextInt()) {
if (input3.nextInt() == 0)
{ break;
} else if (input3.nextInt() < largest)
{ largest = input3.nextInt();
} else if (input3.nextInt() > 0)
{ largestEven += input3.nextInt();
} else if (input3.nextInt() % 2 == 0)
{ countOfAllPositive += input3.nextInt();
} else if (input3.nextInt() < 0)
{ sumOfAll++;
}
}
Scanner input4 = new Scanner(new File("input4.txt"));
while (input4.hasNextInt()) {
if (input4.nextInt() == 0)
{ break;
} else if (input4.nextInt() < largest)
{ largest = input4.nextInt();
} else if (input4.nextInt() > 0)
{ largestEven += input4.nextInt();
} else if (input4.nextInt() % 2 == 0)
{ countOfAllPositive += input4.nextInt();
} else if (input4.nextInt() < 0)
{ sumOfAll++;
}
}
} catch (FileNotFoundException e) {
System.out.println("An error occurred.");
e.printStackTrace(); }
System.out.println("The largest integer in the sequence is " + largest);
System.out.println("The largest even integer in the sequence is " + largestEven);
System.out.println("The count of all positive integers in the sequence is " + countOfAllPositive);
System.out.println("The sum of all integers is " + sumOfAll);
}
}