Java Program to enter Elements of your choice in Array

Enter Elements of your choice in Array

This program illustrate the concept to enter Elements of your choice in Array. Array is a collection of similar types of element.It stores the elements in contiguous memory location.

  • In this program we have defined a maximum size of array is “100” i.e. user can input maximum 100 elements in the array.
  • User can input the elements using Scanner class.
import java.util.*;
class scan
{
public static void main(String arg[])
 { 
  int i,y;
  int x[]=new int[100];
 Scanner kb=new Scanner(System.in);
 System.out.println("Enter how many element you want to entered in array:- ");
   y=kb.nextInt();
   System.out.println("Enter Elements in array:- ");
   for(i=0;i<y;i++)
    { 
     x[i]=kb.nextInt();
    }
   System.out.println("Elements of array are:- ");
   for(i=0;i<y;i++)
     { 
      System.out.println(x[i]);
     }
 }
}

OUTPUT:-

Enter Elements of your choice in Array


Comment below if you are facing any problem.


Also read

Java simple program of defining a array
Java Program to find greatest Element in array
Java program to search an entered element in array


Summary
Java program to Enter elements of your choice in array
Article Name
Java program to Enter elements of your choice in array
Description
This program illustrate the concept to enter Elements of your choice in Array. Array is a collection of similar types of element.
Author
Publisher Name
Scanfcode
Publisher Logo

Leave a Reply

Your email address will not be published. Required fields are marked *