Basically, I am trying to do a while loop, and to keep reading until the line input is $. When that is read, the the loop should exit.
However I am getting a runtime exception as java.util.InputMismatchException.
Here is the code:
while (scan.nextLine() != "$") {
temp1 = scan.nextInt();
temp2 = scan.nextInt();
addEdge(temp1, temp2);
}
You need to use the line you read in (inside the while condition).
When you call nextLine() you not only are checking if it equals “$” but also you are throwing it away.
I assume you are reading input that is like the following: (I bet you are)
try the following:
As a side note: Notice that I switched out your ‘!=’ for a not equals method, this is because a String should not be compared using == or !=