Creating Dynamic Array

java program which set Array size according to user input

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
 
 
package com.spy.javaforlearn;
 
import java.util.Scanner;
 
public class DynamicArray 
{
	public static void main(String[] args) 
	{
 
		Scanner scn=new Scanner(System.in);
 
		System.out.println("Enter size of Array");
 
		int size=scn.nextInt();
 
		int[]  a=new int[size];
 
		System.err.println("Enter Element");
 
		for(int i=0;i<size;i++)
		{
 
			a[i]=scn.nextInt();
 
		}
 
 
		System.out.println("Accessing Array Element");
 
		for(int i=0;i<size;i++)
 
		{
			System.out.println(a[i]);
		}
 
	}
 
}

Leave a Reply

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