-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArrayInverter
More file actions
46 lines (21 loc) · 857 Bytes
/
ArrayInverter
File metadata and controls
46 lines (21 loc) · 857 Bytes
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
import java.util.Arrays;
import java.util.Scanner;
public class exerciosArray1 {
public static void main(String[] args) {
// To create an Arrays and receive values from the User and after invert It.
Scanner scanner = new Scanner(System.in);
int [] arrayEmpty = new int[3];
for( int n = 0; n < arrayEmpty.length; n++){
System.out.println("Insert a number to create the array: ");
int numberChosen1 = scanner.nextInt();
arrayEmpty[n] = numberChosen1;
}
System.out.println(Arrays.toString(arrayEmpty));
for(int i = 0; i < arrayEmpty.length/2; i++){
int temp = arrayEmpty[0];
arrayEmpty[i] = arrayEmpty[arrayEmpty.length - 1 - i];
arrayEmpty[arrayEmpty.length - 1 - i] = temp;
}
System.out.println(Arrays.toString(arrayEmpty));
}
}