-
Notifications
You must be signed in to change notification settings - Fork 0
/
Question21.java
53 lines (51 loc) · 1.12 KB
/
Question21.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
45
46
47
48
49
50
51
52
53
import java.util.*;
class Num{
Scanner sc = new Scanner(System.in);
int array[];
int count=0;
void setData(int n) {
array=new int[n];
for(int i=0;i<array.length;i++) {
System.out.print("Enter element : ");
array[i]=sc.nextInt();
}
}
void getData(){
System.out.print("The array is : [");
for(int j=0;j<array.length;j++) {
System.out.print(array[j]+",");
}
/*Satyam Sekhar Barik
* Regd-no : 2141002032
* sec : CSE-U
* */
System.out.println("]");
}
void reverse() {
int temp[]=new int[array.length];
for(int k=0;k<temp.length;k++) {
temp[k]=array[(array.length-1)-k];
}
for(int m=0;m<array.length;m++) {
array[m]=temp[m];
}
}
}
public class Question21 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
Num n1= new Num();
System.out.println("Enter the array size : ");
int size=sc.nextInt();
n1.setData(size);
sc.close();
n1.getData();
n1.reverse();
System.out.println("The reversed array is : ");
n1.getData();
}
}
/*Satyam Sekhar Barik
* Regd-no : 2141002032
* sec : CSE-U
* */