-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharray_exercise_1.java
28 lines (27 loc) · 951 Bytes
/
array_exercise_1.java
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
import java.util.Arrays;
import java.util.Scanner;
public class array_exercise_1 {
// https://shorturl.at/jyH27 [video link]
public static void main(String[] args) {
Scanner Input = new Scanner(System.in);
System.out.print("How many elements? (max 20): ");
int n = Input.nextInt();
while(n>20 || n<=0){
System.out.print("Invalid number, try again: ");
n = Input.nextInt();
}
int[] numbers = new int[n];
fillArrayofIntegers(numbers);
printArrayOfIntegers(numbers);
}
public static void printArrayOfIntegers(int[] numbers) {
System.out.print("The elements are: ");
System.out.println(Arrays.toString(numbers));
}
public static void fillArrayofIntegers(int[] numbers) {
Scanner Input = new Scanner(System.in);
for(int i = 0; i<numbers.length; i++){
numbers[i] = Input.nextInt();
}
}
}