-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathArrayReverse.java
44 lines (36 loc) · 957 Bytes
/
ArrayReverse.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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import java.util.Scanner;
//take 10 integer inputs from user and store them in an array. Now, copy all the elements in an another array but in reverse order.
public class ArrayReverse {
public static void acceptArray(int arr[])
{
System.out.println("Enter element");
for(int i=0;i<arr.length;i++)
{
Scanner sc =new Scanner(System.in);
arr[i]=sc.nextInt();
}
}
public static void DisplayArray(int arr[])
{
System.out.println();
for(int i=0;i<arr.length;i++)
{
System.out.print(arr[i]+" ");
}
}
public static void CopyArray(int arr[],int arr2[])
{
for(int i=9;i>=0;i--)
{
arr2[9-i]=arr[i];
}
}
public static void main(String[] args) {
int arr[]=new int[10]; //1 2 3 4 5
int arr2[]=new int[10]; //5 4 3 2 1
acceptArray(arr);
DisplayArray(arr);
CopyArray(arr,arr2);
DisplayArray(arr2);
}
}