Greetings. I am trying to write a program that reads from standard input and echoes to the monitor only those lines that begin with "//". It is a prototype for a program which will print out the comments from a java source file. The problem is that the program is echoing everything I type and not just those lines beginning with "//". Here is my code. I must be missing something obvious, but I just can't see it.
Your error is nothing to do with the startsWith() method. There is a stray semi-colon after your if-statement that means that the System.out.println() is not inside the if-statement.
posted 2 years ago
Heavy Sigh I should make a rule for myself. Whenever I am about to post to a message board concerning a debugging problem, make sure I check for the extra semicolon first; I am aware of what can happen when this mistake occurs, not sure why I missed it.