-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReversingArray.java
More file actions
44 lines (39 loc) · 977 Bytes
/
ReversingArray.java
File metadata and controls
44 lines (39 loc) · 977 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
//Program that copies contents of one array to another using length member.
import java.util.Scanner;
public class ReversingArray
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
System.out.print("Enter the size of Array :- ");
int size = sc.nextInt();
int[] array = new int[size];
System.out.print("\nEnter the Array - ");
for(int i=0; i<size; i++)
{
System.out.print("\nEnter the " +(i+1)+" element - ");
array[i]=sc.nextInt();
}
System.out.print("\nEnterd Array is -- ");
for(int i=0; i<size; i++)
{
System.out.print("\t"+array[i]);
}
int start = 0;
int end = size-1;
int temp = 0;
while(start < end)
{
temp = array[start];
array[start] = array[end];
array[end] = temp;
start = start+1;
end = end-1;
}
System.out.print("\nThe Reversed array is :- ");
for(int i=0; i<size; i++)
{
System.out.print("\t"+array[i]);
}
}
}