- //wap to enter the no of elements in an array and store it in an array and display it
- import java.io.*;
- public class Arraydemo {
- public static void main(String[] args) {
- try {
- DataInputStream in = new DataInputStream(System.in);
- System.out.println("Enter the no of elements in an array");
- int n = Integer.parseInt(in.readLine());
- int arr[] = new int[n];
- System.out.println("Enter the elements in an array");
- for (int i = 0; i < n; i++) {
- arr[i] = Integer.parseInt(in.readLine());
- }
- System.out.println("The elements in an array are");
- for (int i = 0; i < n; i++) {
- System.out.println(arr[i]);
- }
- }
- catch (Exception e) {
- }
- }
- }