I need help creating a program that will take user input (using scanner) and place it in a double array. I keep getting runtime errors!
this is what i have so far: import java.util.Scanner; public class Marks{ public static void main(String[]args){ final int VALUES_LENGTH = 25; double[] values = new double[VALUES_LENGTH]; int valueCount = 0; Scanner in = new Scanner(System.in); System.out.println("Please enter some values"); while(in.hasNextDouble()) { if(valueCount< values.length) values[valueCount] = in.nextDouble(); valueCount ++; } for(int i = 0; i<valueCount; i++) System.out.println(values[i]); System.exit(0); }
The only thing that I don't like about your code is using the name "in" for your Scanner. I'm concerned that in is a reserved word, and if nothing else, it is used as part of System.in. Without knowing that actual errors, this is kind of shooting in the dark.
Join our real-time social learning platform and learn together with your friends!