User Input for an Array in Java Programming

This video tutorial explains how to read/receive input for the array from the user.

You will learn how to create an array, how to read input for the all array elements from user, how to display all the all array elements using a loop in detail with example.



Source code for this video tutorial

package learningJava;

import java.util.Scanner;

public class Apples {

public static void main(String[] args) {

 int length;
 Scanner input = new Scanner(System.in);
 
 System.out.println("How many friends name that you are gonna enter");
 length = input.nextInt();  
 
 String[] names = new String[length];
 
 for(int counter = 0; counter < length; counter++){
  System.out.println("Enter the name of friend "+(counter+1));
  names[counter] = input.next();   
 }
 
 input.close();
 
 System.out.println("Your friends are");
 for(int counter = 0; counter < length; counter++){
  System.out.println(names[counter]);
     
 }  

}

}
Back To Top