How to Take Array Input in Java
This is the simple program to take Array Input in Java programming. Here, we will learn the concept of simple int array, input the values in array, and print the values from the array.
I am sure, this easy example will clear your basics input concept of int array. if still you have any doubts about arrays, then comment me. I will try to reply soon.
How to take array input in Java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | //How to get Array Input in Java import java.util.*; public class SimpleArrayInput { public static void main(String args[]) { int arr[]= new int[20] , i; Scanner sc = new Scanner(System.in); System.out.print("Enter 5 elements of array : "); for (i = 0; i < 5; i++) { arr[i] = sc.nextInt(); } System.out.print("Entered Array elements are : "); for (i = 0; i < 5; i++) { System.out.print(arr[i] + " "); } } } |
Output
Check out our other Java Programming Examples