This is what I got so far, I'm trying to loop the user input and have the variables from the user input added to the list below. I tried to put the user input part into a loop but was not able to transfer the variables into the array
// inport
import java.util.*;
// Main program
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in); //Scans the user inputs and puts it into array
System.out.print("Enter a number- ");
int a = sc.nextInt();
System.out.print("Enter a number- ");
int b = sc.nextInt();
System.out.print("Enter a number- ");
int c = sc.nextInt();
System.out.print("Enter a number- ");
int d = sc.nextInt();
System.out.print("Enter a number- ");
int e = sc.nextInt();
System.out.print("Enter a number- ");
int f = sc.nextInt();
System.out.print("Enter a number- ");
int g = sc.nextInt();
System.out.print("Enter a number- ");
int h = sc.nextInt();
System.out.print("Enter a number- ");
int i = sc.nextInt();
System.out.print("Enter a number- ");
int j = sc.nextInt();
int[] array = { a, b, c, d, e, f, g, h, i, j };
}
}
This is what I tried:
import java.util.*;
class Main {
public static void main(String[] args) {
for (int i = 0; i < 10; i++) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter in a number- ");
int a = sc.nextInt();
return a;
}
int[] ary = {a, a, a, a, a, a, a, a, a, a};
}
}