-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathProblem-1.java
98 lines (73 loc) · 1.49 KB
/
Problem-1.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/**
* @author AkashGoyal
* @date 24/05/2021
*/
/**
--------------------- Problem----------->> Reverse the array
Problem Link :- https://practice.geeksforgeeks.org/problems/reverse-an-array/0
*/
//Method-1 (Changing the array)
import java.lang.*;
import java.io.*;
class GFG
{
public static void main (String[] args)
{
//code
Scanner scan=new Scanner(System.in);
int t=scan.nextInt();
for(int j=0;j<t;j++)
{
int n=scan.nextInt();
int arr[]=new int[n];
for(int i=0;i<n;i++)
{
arr[i]=scan.nextInt();
}
int left=0;
int right=n-1;
while(left<right)
{
int temp=arr[right];
arr[right]=arr[left];
arr[left]=temp;
left++;
right--;
}
for(int i=0;i<n;i++)
{
System.out.print(arr[i]+" ");
}
System.out.println();
}
}
}
//----------------------------------------------------------------------------------------------------
//Method-2 Printing the array elements from last
import java.lang.*;
import java.io.*;
class GFG
{
public static void main (String[] args)
{
//code
Scanner scan=new Scanner(System.in);
int T=scan.nextInt();
for(int i=0;i<T;i++)
{
int N=scan.nextInt();
int arr[]=new int[N];
//Taking Input
for(int j=0;j<N;j++)
{
arr[j]=scan.nextInt();
}
//Printing in reverse Order
for(int j=N-1;j>=0;j--)
{
System.out.print(arr[j]+" ");
}
System.out.println();
}
}
}