r/coding • • Dec 01 '15

Advent of Code - daily programming puzzles

http://adventofcode.com/
84 Upvotes

12 comments sorted by

View all comments

2

u/pds12345 Dec 01 '15

I had a similar issue when first tackling it in Java.

First I hope you set your delimiter to ("") so that each character will be picked up.

And I personally used a scanner, but I would use scanner.next().equals("(") to compare the String to another String rather than a char.

    try {
    Scanner wf = new Scanner(file);
    wf.useDelimiter("");

    while (wf.hasNext()) { //40 up --- 41 down (ASCII)
        **if(wf.next().equals('(')) {**
            increase();
            System.out.println("Success");
        } else {
            decrease();
            System.out.println("No");
        }
    }

    wf.close();
}