Basically, I want to create a program that will find the slope of two coordinates. I've done this, but I want the program to ask if it wants to re-start-- as in, to find a different slope, without the user having to exit and re-open the program. This is my code, minus all the unnecessary bits:
import java.io.Console;
public class slopeFinder{
public static void main(String[] args) {
Console console = System.console();
do{
/* code to find slope here.
It asks for the X1, Y1, X2 and Y2 values using the readLine method on console
and then it parses the Strings and then does the math, obviously. Then it
prints out the slope. */
}
String cont = console.readLine(" Find another slope? Y/N ");
}
while (cont.equalsIgnoreCase("Y"));
}
}
The issue I'm having is that I'm getting the error "cannot find symbol" in reference to the line that says
while(cont.equalsIgnoreCase("Y"));
I don't understand what I'm doing wrong? Everything is spelled correctly..
cont
is declared inside the loop, so it's not within scope in the loop's condition. You should declare it before the loop.
String cont = "Y";
do {
...
cont = console.readLine(" Find another slope? Y/N ");
} while (cont.equalsIgnoreCase("Y"));