codescracker


java

Java One Dimensional Array Program



« Previous Program Next Program »


One Dimensional Array Program

To print one dimensional array in Java Programming you have to use only one for loop as shown in the following program.

Java Programming Code on One Dimensional (1D) Array

Following Java Program ask to the user to enter the array size and then ask to enter the element of the array to store the elements in the array, then finally display the array elements on the screen:

/* Java Program Example - One Dimensional Array Program */
		
import java.util.Scanner;

public class JavaProgram
{
   public static void main(String args[])
   {
   
       int arr[] = new int[50];
       int n, i;
       Scanner scan = new Scanner(System.in);
	   
       System.out.print("How Many Element You Want to Store in Array ? ");
       n = scan.nextInt();
	   
       System.out.print("Enter " + n + " Element to Store in Array : ");
       for(i=0; i<n; i++)
       {
           arr[i] = scan.nextInt();
       }
	   
       System.out.print("Elements in Array is :\n");
       for(i=0; i<n; i++)
       {
           System.out.print(arr[i] + "  ");
       }
	   
   }
}

When the above Java Program is compile and executed, it will produce the following output:

Java Program one dimensional array

Same Program in Other Languages

You may also like to learn and practice the same program in other popular programming languages:


« Previous Program Next Program »



Tools
Calculator

Quick Links
Signup - Login - Give Online Test