Answer to Question #9921 in Java | JSP | JSF for Kay-Z

Question #9921
How do I make a user enter values into an array?
1
Expert's answer
2012-05-24T08:56:17-0400
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!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS