This is obviously homework but I am having issues with part of the assignment here is that part
"Start by asking the user for how many double values do they want you to read in. Then allows them to input them one at a time. An exception should be thrown if given faulty values. You will store the values read in into an array."
The issue I am having is with the for loop that asks for the user to input the numbers that they want it throws 5 errors I can't figure out or is there an easier way to get user input?. Here is that code for that
//import statements
import java.util.*; //for scanner class
// class beginning
class StandardDev {
public static void main(String[] args ) {
//Declare variables area
Scanner input = new Scanner (System.in);
//Collect inputs from user or read in data here
System.out.println("Welcome to my Standard Deviation and average program!");
System.out.println("how many numbers do you want to enter? ");
int number =input.nextInt();
double [] value = new double [number];
//Echo input values back to user here
System.out.println("you want to enter in "+number+" numbers, lets start");
//main code and calculations to do
int i;
for ( i = 0;, i <number;, i++){
value[i] = input.nextDouble();
System.prinln("here are the numbers you have entered "+value+"!");
}
//Output results here
and if anyone can tell me how to check if the number entered isn't a valid input (is it any different if this wasn't an array?) and am I correctly entering in doubles for the program?
Aucun commentaire:
Enregistrer un commentaire