This is my situation:
I need code to start the cycle over and over, asking the same question to the user until the user types “q” for any point to end / exit the cycle, thereby exiting the program.
The problem is that I tried to use the do-while / while loop, and these loops execute only if the conditions are true. But I need the condition ("q") to be false in order to continue the loop. If the condition is true (input.equals ("q")), then it just has nothing, because instead of the integer / double, it will use the string ("q") to calculate the distance.
I already figured out how to get the distance, the code works fine, but is there any work so that I can make the loop last while the condition is false?
and by the way, I just don't learn much java just in case ...
.
import java.*;
public class Points {
public static void main(String[] args){
java.util.Scanner input = new java.util.Scanner(System.in);
System.out.print("Enter the first X coordinate: ");
double x1 = input.nextDouble();
System.out.print("Enter the first Y coordinate: ");
double y1 = input.nextDouble();
System.out.print("Enter the second X coordinate: ");
double x2 = input.nextDouble();
System.out.print("Enter the second Y coordinate: ");
double y2 = input.nextDouble();
System.out.println("(" + x1 + ", " + y1 + ")" + " " + "(" + x2 + ", " + y2+ ")");
double getSolution = Math.sqrt(((x2-x1) * (x2-x1)) + ((y2-y1) * (y2-y1)));
System.out.println(getSolution);
}
}'
source
share