Skip to content

Instantly share code, notes, and snippets.

/test.java Secret

Created December 6, 2013 03:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/44f551cf57b8ba9309cb to your computer and use it in GitHub Desktop.
Save anonymous/44f551cf57b8ba9309cb to your computer and use it in GitHub Desktop.
why isn't character switch working for ' v ' and ' | '?
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
public class test {
public test(String file) throws Exception {
// fields
BufferedReader input;
int scale, width, length, bombs;
// constructor - creates graph from input file
String line;
char ch;
// read input file, if exists, throw an exception if it doesn't exist
try {
input = new BufferedReader(new FileReader(file));
} catch (FileNotFoundException e) {
throw new Exception("Error: Input file doesn't exist!");
}
// take the first 4 integer values from input
scale = Integer.parseInt(input.readLine());
width = Integer.parseInt(input.readLine());
length = Integer.parseInt(input.readLine());
bombs = Integer.parseInt(input.readLine());
// get next line
line = input.readLine();
// loop through remaining lines of file
while (line != null) {
// get characters in the line
for (int j = 0; j < line.length(); j++) {
// if character is even, it is a node
ch = line.charAt(j);
if (j % 2 == 0) {
System.out.println("character even and is: " + ch);
switch (ch) {
case 's':
System.out.println("s test worked");
break;
case 'e':
System.out.println("e test worked");
break;
case 'o': // increase the node count
break;
}
}
// else character is odd, it is an edge
else {
System.out.println("character odd and is: " + ch);
System.out.println(ch == 'v');
System.out.println(ch == '|');
switch (ch) {
// horizontal wall
case 'h':
System.out.println("h test worked");
break;
// horizontal hall
case '-':
System.out.println("- test worked");
break;
// vertical wall
case 'v':
System.out.println("v test worked");
break;
// vertical hall
case '|':
System.out.println("| test worked");
break;
// unbreakable wall
case ' ': // don't do anything
break;
}
}
}
line = input.readLine();
}
}
public static void main (String [] args) throws Exception {
test test = new test("test.txt");
}
}
50
5
3
0
s-o o-o-o
| v v | v
o-o-o-oho
v | v |
o-o-o-e-o
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment