Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit af59058

Browse files
author
Ram swaroop
committed
initial commit
1 parent 168f7a8 commit af59058

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package me.ramswaroop.misc;
2+
3+
import java.io.BufferedReader;
4+
import java.io.FileReader;
5+
import java.io.IOException;
6+
import java.util.ArrayList;
7+
import java.util.List;
8+
9+
/**
10+
* Created by IntelliJ IDEA.
11+
*
12+
* @author: ramswaroop
13+
* @date: 9/15/15
14+
* @time: 11:15 PM
15+
*/
16+
public class Parenthesis {
17+
18+
public static String isWellFormed(String input) {
19+
int len = input.length() - 1;
20+
for (int i = 0; i < len / 2; i++) {
21+
if (input.charAt(0) != input.charAt(len - i - 1)) {
22+
return "False";
23+
}
24+
}
25+
return "True";
26+
}
27+
28+
public static void areParenthesisWellFormed(String filename) {
29+
List<String> input = readFile(filename);
30+
for (int i = 0; i < input.size(); i++) {
31+
isWellFormed(input.get(i));
32+
}
33+
}
34+
35+
public static List<String> readFile(String filename) {
36+
List<String> input = new ArrayList<>();
37+
BufferedReader br = null;
38+
39+
try {
40+
41+
String sCurrentLine;
42+
43+
br = new BufferedReader(new FileReader(filename));
44+
45+
while ((sCurrentLine = br.readLine()) != null) {
46+
input.add(sCurrentLine);
47+
}
48+
49+
} catch (IOException e) {
50+
e.printStackTrace();
51+
} finally {
52+
try {
53+
if (br != null) br.close();
54+
} catch (IOException ex) {
55+
ex.printStackTrace();
56+
}
57+
}
58+
return input;
59+
}
60+
61+
public static void main(String a[]) {
62+
areParenthesisWellFormed(a[0]);
63+
}
64+
}

0 commit comments

Comments
 (0)