pTutorial

New way to learn Programming

Java array example programs

User define Java program to print array. We use Scanner class to enter integer(nextInt() for integer) through the keyboard that belongs to the java.util package.

User define java array example

//user define java program to print array
import java.util.Scanner;
public class ArrayUser 
{
    static int n;
    public static void main(String[] args) {
    Scanner uk = new Scanner(System.in);
    System.out.println("Enter the number of element");
    n = uk.nextInt();
    int x[] = new int[n];	

    
    System.out.println("Enter "+ n +" numbers");
    for(int l=0;l<x.length;l++){
        x[l]= uk.nextInt();
    }
    
    System.out.println("OuTput:");
    System.out.println("Entered numbers are :");
    for(int l=0;l<x.length;l++){
        System.out.println(x[l]);
    }
}
}

Output

Enter the number of element
4
Enter 4 numbers
12
38
07
89
OuTput:
Entered numbers are :
12
38
7
89

See Also


QUOTES OF THE DAY

Goal is tired by fire, brave men by adversity.

LIKE ON FACEBOOK

+1 ON GOOGLE

SHARE ON TWITTER