To learn use of single dimensional array by defining the array dynamically.


To learn use of single dimensional array by defining the array dynamically.

Program:

import java.util.Scanner;

public class DynamicArray {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        System.out.print("How many elements you want to enter : ");

        int num = sc.nextInt();

        System.out.print("Enter Elements of Array : ");

        int arr[] = new int[num];

        for (int i = 0; i < num; i++) {

            arr[i] = sc.nextInt();

        }

        sc.close();

        System.out.println("Entered Elements Of Array Are : ");

        for (int i = 0; i < num; i++) {

            System.out.println(arr[i]);

        }

    }

}


OutPut:

How many elements you want to enter : 

4

Enter Elements of Array : 

54

53

27

95

Entered Elements Of Array Are : 

54

53

27

95