-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArrayPrint_VoidMethod.java
More file actions
153 lines (144 loc) · 4.52 KB
/
Copy pathArrayPrint_VoidMethod.java
File metadata and controls
153 lines (144 loc) · 4.52 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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
import java.util.Scanner;
public class ArrayPrint_VoidMethod {
//VOID METHODS FOR ARRAY PRINTING
static void displayB(byte b[]){
for(int i=0; i<b.length; i++){
System.out.print(b[i] + " ");
}
}
static void displayS(short s[]){
for(int i=0; i<s.length; i++){
System.out.print(s[i] + " ");
}
}
static void displayI(int i1[]){
for(int i=0; i<i1.length; i++){
System.out.print(i1[i] + " ");
}
}
static void displayL(long l[]){
for(int i=0; i<l.length; i++){
System.out.print(l[i] + " ");
}
}
static void displayF(float f[]){
for(int i=0; i<f.length; i++){
System.out.print(f[i] + " ");
}
}
static void displayD(double d[]){
for(int i=0; i<d.length; i++){
System.out.print(d[i] + " ");
}
}
static void displayC(char c[]){
for(int i=0; i<c.length; i++){
System.out.print(c[i] + " ");
}
}
static void displayBool(boolean bool[]){
for(int i=0; i<bool.length; i++){
System.out.print(bool[i] + " ");
}
}
static void displayStr(String str[]){
for(int i=0; i<str.length; i++){
System.out.print(str[i] + " ");
}
}
public static void main(String args[]){
Scanner sc= new Scanner(System.in);
//ALL PRIMITIVE DATATYPES ARRAY USING VOID METHOD
//BYTE
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();
}
displayB(b);
System.out.println();
//SHORT
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();
}
displayS(s);
System.out.println();
//INT
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();
}
displayI(i1);
System.out.println();
//LONG
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();
}
displayL(l);
System.out.println();
//FLOAT
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();
}
displayF(f);
System.out.println();
//DOUBLE
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();
}
displayD(d);
System.out.println();
//CHAR
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);
}
displayC(c);
System.out.println();
//BOOLEAN
System.out.print("Enter size for boolean array: ");
int size_bl= sc.nextInt();
boolean bool[]= new boolean[size_bl];
System.out.print("Enter elements for boolean array: ");
for(int i=0; i<bool.length; i++){
bool[i]= sc.nextBoolean();
}
displayBool(bool);
System.out.println();
//STRING
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();
sc.nextLine();
}
displayStr(str);
System.out.println();
}
}