forked from FatimaAlazazi/DataStructure2021
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReversArray.java
More file actions
35 lines (31 loc) · 809 Bytes
/
ReversArray.java
File metadata and controls
35 lines (31 loc) · 809 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
package Task2;
public class ReversArray {
static int [] a = {7,2,4,5,6,3,1};
static public void Print()
{
System.out.print("[ ");
for (int i = 0; i <a.length ; i++) {
if(i==a.length-1)
System.out.print(a[i]+" ]");
else
System.out.print(a[i]+" , ");
}
}
static public void Revers()
{
int x=a.length-1;
for (int i = 0; i <a.length/2 ; i++) {
int temp = a[i];
a[i]=a[x];
a[x]=temp;
x--;
}
}
public static void main(String[] args) {
System.out.println("Before Revers :");
Print();
Revers();
System.out.println("\nAfter Revers :");
Print();
}
}