So my instructor told us to submit our assignment which I've done. She has an online java compiler that checks if the answer is right. I looked at the report and it has the right outputs and everything and below is this that makes my answers wrong:
Exception in thread "main" java.util.NoSuchElementException
at java.util.Scanner.throwFor(Scanner.java:838)
at java.util.Scanner.next(Scanner.java:1461)
at java.util.Scanner.nextInt(Scanner.java:2091)
at java.util.Scanner.nextInt(Scanner.java:2050)
at Assignment2.main(Assignment2.java:30)
I really have no idea whats wrong.
Here's my code:
import java.util.Scanner; // uses the Scanner package located in the "java.util" directory
public class Assignment2
{
public static void main (String[] args)
{
Scanner console = new Scanner(System.in); // creates a new scanner
int num; //initializing all variables and values
int max = 0;
int pos_sum = 0;
int odd_sum = 0;
int evens = 0;
while (true) // "while this is true" execute the if statements
{
num = console.nextInt(); // num is scanned through scan as a Integer
if(num > max) // This calculates whether or not the integer is the greatest amount
{
max = num; // sets max integer equal to the number
}
if(num > 0) // Adds the number to the sum if the integer is positive.
{
pos_sum = pos_sum + num;
}
if (num % 2 != 0) // Adds the integer to the sum of odds if the number is odd
{
odd_sum = odd_sum + num;
}
if (num % 2 == 0) // This counts the number of even numbers
{
evens++;
}
// prints out the statements and the following information
System.out.println("The maximum integer is " + max + "\n"
+ "The sum of the positive integers is " + pos_sum + "\n"
+ "The sum of the odd integers is " + odd_sum + "\n"
+ "The count of even integers in the sequence is " + evens + "\n");
}
}
}