I know this is easy but I think some people out there are interested
in my idea about storing user input in an array...... i read it some where and thought about bringing it much closer to you.

import java.util.Scanner;

 * @author BUSKER-OTT
public class USERINPUT {

    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        //allow user  input;
        System.out.println("How many numbers do you want to enter?");
        int num = input.nextInt();
        int array[] = new int[num];
        System.out.println("Enter the " + num + " numbers now.");
            for (int i = 0 ; i < array.length; i++ ) {
                 array[i] = input.nextInt();
            //you notice that now the elements have been stored in the array .. array[]
            System.out.println("These are the numbers you have entered.");
    //this method prints the elements in an array......
    //if this case is true, then that's enough to prove to you that the user input has //been stored in an array!!!!!!!

    public static void printArray(int arr[]){
        int n = arr.length;
        for (int i = 0; i < n; i++) {
            System.out.print(arr[i] + " ");

Recommended Answers

All 3 Replies

what exactly is your question?
if this is the "right way" to store "user info"?
that would depend on what info you want to store and how you are planning to use it.

what you have shown above has nothing to do with storing user info, you're just creating an array of integers, and displaying them afterwards.

if that is what you wanted, then sure, nothing wrong with it.

yeah Stultuske.. that's pretty it, just storing integers input by the user in an array......

Here's nothing particularly wrong with this, as far as it goes.
You may want to do something different when the user types a letter instead of a valid integer.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.