Skip to content

Commit 53f5090

Browse files
authored
Add files via upload
1 parent 0f8b775 commit 53f5090

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

JavaArray05.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*Write a Java program that asks the user for the length of an array and then creates an integer array of that length by taking inputs from the user. Then, reverse the original array without creating any new array and print it. [In-place reverse]*/
2+
3+
import java.util.Scanner;
4+
public class JavaArray05{
5+
public static void main(String [] args){
6+
Scanner sc= new Scanner(System.in);
7+
int n=sc.nextInt();
8+
int[]arr= new int[n];
9+
int h=n-1;
10+
for(int i=0;i<n;i++){
11+
arr[i]=sc.nextInt();}
12+
for(int k=0;k<n/2;k++){
13+
int t;
14+
t=arr[k];
15+
arr[k]=arr[h];
16+
arr[h]=t;
17+
h--;}
18+
for(int i=0;i<n;i++){
19+
System.out.println(arr[i]);}
20+
}
21+
}

0 commit comments

Comments
 (0)