I just started learning Java, and I'm pretty confused at this point. I am trying to make a program in which any number of numbers the user will enter will be calculated, but I cannot figure out how to allow the user to enter as many numbers as they want. Right now, the code just allows them to make 1 number before it becomes average.
Notes: There is a good chance, I am writing this completely wrong, I am doing this to find out what I still know
I am using eclipse
I study at www.thenewboston.org
Here is the code:
import java.util.Scanner; class MainClass { public static void main(String[] args){ System.out.println("Enter Grades Now"); Scanner input = new Scanner(System.in); double input2 = input.nextDouble(); System.out.println(average(input2)); } public static double average(double...numbers){ double total=0; for(double x:numbers) total+=x; return total/numbers.length; } }
source share