Solved programming problem

Array List Input Output in Java.

Source code

package inputoutput;

import java.util.Scanner;

import java.util.ArrayList; ///import java Array List

public class InputOutput

{

 

    public static void main(String[] args)

    {

        Scanner s = new Scanner(System.in);

        ArrayList<Integer>Array = new ArrayList<Integer>(); ///declare

       

        System.out.println("Enter Array Size: ");

        int n = s.nextInt();

       

        System.out.println("Enter Array Element: ");

        for(int i =0;i<n;i++)

        {

            int temp = s.nextInt();

            Array.add(temp);     /// push back to array list  

        }

       

        System.out.println("Your Arrray");

        for(int x: Array) ///for each loop for print

        {

            System.out.println(x);

        }

    }

   

}

Output

Entera rray size:

5

Enter array element:

1 2 3 4 5

Your array:

1

2

3

4

5

Join the discussion

Add your comment