-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArrayPrint_ReturnMethod.java
More file actions
191 lines (180 loc) · 5.42 KB
/
Copy pathArrayPrint_ReturnMethod.java
File metadata and controls
191 lines (180 loc) · 5.42 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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
import java.util.Scanner;
public class ArrayPrint_ReturnMethod {
//RETURN TYPE METHODS FOR ARRAY STORING
static byte[] arrayB(byte b[]){
return b;
}
static void displayB(byte b1[]){
for(int i=0; i<b1.length; i++){
System.out.print(b1[i] + " ");
}
}
static short[] arrayS(short s[]){
return s;
}
static void displayS(short s1[]){
for(int i=0; i<s1.length; i++){
System.out.print(s1[i] + " ");
}
}
static int[] arrayI(int i1[]){
return i1;
}
static void displayI(int i2[]){
for(int i=0; i<i2.length; i++){
System.out.print(i2[i] + " ");
}
}
static long[] arrayL(long l[]){
return l;
}
static void displayL(long l1[]){
for(int i=0; i<l1.length; i++){
System.out.print(l1[i] + " ");
}
}
static float[] arrayF(float f[]){
return f;
}
static void displayF(float f1[]){
for(int i=0; i<f1.length; i++){
System.out.print(f1[i] + " ");
}
}
static double[] arrayD(double d[]){
return d;
}
static void displayD(double d1[]){
for(int i=0; i<d1.length; i++){
System.out.print(d1[i] + " ");
}
}
static char[] arrayC(char c[]){
return c;
}
static void displayC(char c1[]){
for(int i=0; i<c1.length; i++){
System.out.print(c1[i] + " ");
}
}
static boolean[] arrayBool(boolean bool[]){
return bool;
}
static void displayBool(boolean bool[]){
for(int i=0; i<bool.length; i++){
System.out.print(bool[i] + " ");
}
}
static String[] arrayStr(String str[]){
return str;
}
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 STORING USING RETURN TYPE 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();
}
byte b1[]= arrayB(b);
displayB(b1);
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();
}
short s1[]= arrayS(s);
displayS(s1);
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();
}
int i2[]= arrayI(i1);
displayI(i2);
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();
}
long l1[]= arrayL(l);
displayL(l1);
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();
}
float f1[]= arrayF(f);
displayF(f1);
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();
}
double d1[]= arrayD(d);
displayD(d1);
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);
}
char c1[]= arrayC(c);
displayC(c1);
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();
}
boolean bool1[] = arrayBool(bool);
displayBool(bool1);
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();
}
String str1[] = arrayStr(str);
displayStr(str1);
System.out.println();
}
}