Skip to content

Commit d32ed3e

Browse files
committed
Reverse Array
1 parent 8d4347f commit d32ed3e

File tree

6 files changed

+30
-1
lines changed

6 files changed

+30
-1
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/.metadata/
Binary file not shown.
Binary file not shown.

ExceptionHandling/src/com/cdac/CheckedExceptions.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
package com.cdac;
22

3+
import java.io.FileNotFoundException;
34
import java.io.FileReader;
45

56
public class CheckedExceptions {
67

7-
public static void main(String[] args) {
8+
public static void main(String[] args) throws FileNotFoundException {
89
//this exception checked at compile time
910
//handle this with try catch to compile the program
1011
FileReader filereader = new FileReader("FilePath");
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.java.array;
2+
3+
/*
4+
* Author - Suraj Subramanian
5+
* */
6+
7+
public class ReverseArray {
8+
9+
public static void main(String[] args) {
10+
11+
int array[]= {1,2,3,4,5,6,7,8,9,10};
12+
int temp;
13+
14+
//run the loop n/2 times and swap positions one by one
15+
for(int i=0;i<array.length/2;i++) {
16+
temp=array[i];
17+
array[i]=array[array.length-1-i]; // array.length-1-i instead of another variable to point to end of array
18+
array[array.length-1-i]=temp;
19+
}
20+
21+
//print the reversed array
22+
for(int x : array) {
23+
System.out.println(x);
24+
}
25+
}
26+
27+
}

0 commit comments

Comments
 (0)