Everything outputs exactly as it should in the program and in eclipse, no errors whatsoever but then it gives a few errors on ASU submission site.
// Description: This class reads doubles from the keyboard, logs them to an array
// and finds the lowest value in the array along with the sum of
// all positive numbers and the count of negative numbers.
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.Scanner;
public class Assignment2 {
public static void main(String[] args) { //Main class, takes care of beginning and end operations
NumberFormat single = new DecimalFormat("###,###,###,###,##0"); //These alter the outputs
NumberFormat $ = new DecimalFormat("$###,###,###,###,##0.00"); //later in the code
double[] nums = new double[100];
int count = 0;
@SuppressWarnings("resource") //Eclipse gives an error without this
Scanner scan = new Scanner(System.in);
while(nums[count] < 100){
//have a count to keep track of input numbers
//input values assigned to nums
for(int i = 0; i < 100; i++) {
double temp = scan.nextDouble();
nums[i] = temp;
if (nums[i] == 0){
break;
}
}
double min = findMin(nums, count);
double positive = computePositiveSum(nums, count);
int negative = countNegative(nums, count);
System.out.println("The minimum number is " + single.format(min));
System.out.println("The sum of the positive numbers is " + $.format(positive));
System.out.println("The total number of negative numbers is " + single.format(negative));
}
This is the main method, the 3 listed aren't important because the error is on line 27, the double temp = scan.nextDouble(); I realize it's unnecessary but I used thsat to see if it would fix the problem because nums[i] = scan.nextDouble(); had the error as well. The submission site results are as follows:
Grade
Assignment2
Compilation
2 pts. - Passed
Functionality
Test #1
Program Output
The minimum number is 0
The sum of the positive numbers is $0.00
The total number of negative numbers is 0
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.nextDouble(Scanner.java:2387)
at Assignment2.main(Assignment2.java:27)
Expected Output
The minimum number is 0
The sum of the positive numbers is $0.00
The total number of negative numbers is 0
0 pts. - Failure
Can anyone help me understand what I'm doing wrong? Also any criticism on my coding practices are welcome, I'm a freshman and I'm having a hard time learning java so if I can have perfect "grammar", so to speak, I'll take it. Thanks in advance!