- Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathreverse_array.java
More file actions
Latest commit
27 lines (24 loc) · 958 Bytes
/
Copy pathreverse_array.java
File metadata and controls
27 lines (24 loc) · 958 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
importjava.util.Scanner;
publicclassMain{
publicstaticvoidmain(String[] args){
Scannersc = newScanner(System.in);
intn = sc.nextInt(); //taking input for size of array
intarray[] = newint[n]; //declare new array
for(inti=0; i<n; i++){
array[i] = sc.nextInt(); //for loop for input first array
}
System.out.println("ORIGINAL ARRAY");
for(inti=0; i<array.length; i++){
System.out.print(" "+array[i]); //for loop for print first array
}
System.out.println(); // for next line
intarray2[] = newint[array.length]; //declare new array2 (second array)
for (inti = 0; i < array.length; i++) { //for loop for copy array to array2
array2[i] = array[i];
}
System.out.println("REVERSED ARRAY OR ARRAY 2");
for(inti= array.length-1; i>=0; i--){
System.out.print(" "+array2[i]); //for loop for reverse and print array2
}
}
}