How do I make a user enter values into an array?
import java.util.Scanner;
public class Test {
public static void
main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.println("Please enter the size of an array: ");
int size =
in.nextInt();
int [] array = new int[size];
for (int i =
0; i < size; i++) {
System.out.println("Please enter element #" +
i + ": ");
array[i] = in.nextInt();
}
System.out.println("Here is your array: ");
for (int i = 0; i <
size; i++)
System.out.print(array[i] + " ");
}
}
Need a fast expert's response?
Submit order
and get a quick answer at the best price
for any assignment or question with DETAILED EXPLANATIONS!
Learn more about our help with Assignments:
JavaJSPJSF