-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDynamicArray.java
More file actions
107 lines (97 loc) · 3.36 KB
/
Copy pathDynamicArray.java
File metadata and controls
107 lines (97 loc) · 3.36 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import java.util.Scanner;
public class DynamicArray {
public static void main(String args[]){
Scanner sc= new Scanner(System.in);
//CREATING AND PRINTING DYNAMIC ARRAY
//PRIMITIVE DATATYPES
System.out.print("Enter size for byte array: ");
int size_b= sc.nextInt();
byte b[]= new byte[size_b];
System.out.print("Enter elements for byte array: ");
for(int i=0; i<b.length; i++){
b[i]= sc.nextByte();
}
for(int i=0; i<b.length; i++){
System.out.print(b[i] + " ");
}
System.out.println();
System.out.print("Enter size for short array: ");
int size_s= sc.nextInt();
short s[]= new short[size_s];
System.out.print("Enter elements for short array: ");
for(int i=0; i<s.length; i++){
s[i]= sc.nextShort();
}
for(int i=0; i<s.length; i++){
System.out.print(s[i] + " ");
}
System.out.println();
System.out.print("Enter size for int array: ");
int size_i= sc.nextInt();
int i1[]= new int[size_i];
System.out.print("Enter elements for int array: ");
for(int i=0; i<i1.length; i++){
i1[i]= sc.nextInt();
}
for(int i=0; i<i1.length; i++){
System.out.print(i1[i] + " ");
}
System.out.println();
System.out.print("Enter size for long array: ");
int size_l= sc.nextInt();
long l[]= new long[size_l];
System.out.print("Enter elements for long array: ");
for(int i=0; i<l.length; i++){
l[i]= sc.nextLong();
}
for(int i=0; i<l.length; i++){
System.out.print(l[i] + " ");
}
System.out.println();
System.out.print("Enter size for float array: ");
int size_f= sc.nextInt();
float f[]= new float[size_f];
System.out.print("Enter elements for float array: ");
for(int i=0; i<f.length; i++){
f[i]= sc.nextFloat();
}
for(int i=0; i<f.length; i++){
System.out.print(f[i] + " ");
}
System.out.println();
System.out.print("Enter size for double array: ");
int size_d= sc.nextInt();
double d[]= new double[size_d];
System.out.print("Enter elements for double array: ");
for(int i=0; i<d.length; i++){
d[i]= sc.nextDouble();
}
for(int i=0; i<d.length; i++){
System.out.print(d[i] + " ");
}
System.out.println();
System.out.print("Enter size for char array: ");
int size_c= sc.nextInt();
char c[]= new char[size_c];
System.out.print("Enter elements for char array: ");
for(int i=0; i<c.length; i++){
c[i]= sc.next().charAt(0);
}
for(int i=0; i<c.length; i++){
System.out.print(c[i] + " ");
}
System.out.println();
//STRING WRAPPER CLASS
System.out.print("Enter size for string array: ");
int size_str= sc.nextInt();
String str[]= new String[size_str];
System.out.print("Enter elements for string array: ");
for(int i=0; i<str.length; i++){
str[i]= sc.next();
}
for(int i=0; i<str.length; i++){
System.out.print(str[i] + " ");
}
System.out.println();
}
}