-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathReadArray.java
More file actions
44 lines (34 loc) · 1.06 KB
/
ReadArray.java
File metadata and controls
44 lines (34 loc) · 1.06 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
package Online_Code_Samples.Week2;
import java.util.Arrays;
import java.util.Scanner;
public class ReadArray {
static Scanner scanner = new Scanner(System.in);
public static int[] readInteger(){
int[] num = new int[5];
int count = 0;
System.out.println("Input 5 numbers ");
do {
int numbers = scanner.nextInt();
num[count] = numbers;
count++;
} while (count < 5);
return num;
}
public static String[] readStrings(){
// Scanner scanner = new Scanner(System.in);
String[] stringArray = new String[5];
int count = 0;
do {
System.out.println("Enter A Strings ");
String strings = scanner.nextLine();
stringArray[count] = strings;
count++;
} while (count < 5);
// scanner.close();
return stringArray;
}
public static void main(String[] args) {
System.out.println(Arrays.toString(readInteger()));
System.out.println(Arrays.toString(readStrings()));
}
}