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.");
            printArray(array);
          
        }
    //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] + " ");
        
        }
        
    }
    
    
}

Edited 5 Years Ago by peter_budo: Keep It Clear - Do use code tags when posting any code

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.

This article has been dead for over six months. Start a new discussion instead.