-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQuestion124_ReverseArray.java
More file actions
51 lines (35 loc) · 1.14 KB
/
Question124_ReverseArray.java
File metadata and controls
51 lines (35 loc) · 1.14 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
package week7_Array_2D_ArrayList;
import java.util.Arrays;
import java.util.Scanner;
public class Question124_ReverseArray {
public static void main(String[] args) {
// olcay // Jul 23, 2020
/* Given an array nums with 7 integers already assigned, write code to reverse it.
Do not use any additional arrays or Strings.
Example:
nums -> [4, 3, 2, 44, 1, 100, 55]
change it to:
nums -> [55, 100, 1, 44, 2, 3, 4]
*/
Scanner input = new Scanner(System.in);
System.out.println("Enter 7 numbers: ");
int[] nums = {input.nextInt(), input.nextInt(),input.nextInt(),input.nextInt(),input.nextInt(),input.nextInt(),input.nextInt(),input.nextInt(),input.nextInt(),input.nextInt()};
for(int i=0;i<nums.length/2;i++) {
int temp=nums[i];
nums[i]=nums[nums.length-1-i];
nums[nums.length-1-i]=temp;
}
// int first=nums[0];
// nums[0]=nums[6];
// nums[6]=first;
//
// int second = nums[1];
// nums[1]=nums[5];
// nums[5]=second;
//
// int third = nums[2];
// nums[2]=nums[4];
// nums[4]=third;
System.out.println(Arrays.toString(nums));
}
}