无论最后的输入如何,我的do-while循环都不会继续

时间:2017-03-28 15:10:47

标签: java do-while

以下是我的代码。这是初学者级Java中的一个简单的类练习。只要用户想要输入点,我就要计算点之间的距离。当我运行我的代码(除了格式化小数),它完美地工作,但它在第一次运行后终止。有人可以帮忙吗?这是我的代码:

import java.util.Scanner;

public class Distance {     字符串a;

public static void main( String[] args){
    Scanner input = new Scanner(System.in);
    String a = "y";
    do {
        System.out.print("Enter x1:");
        double x1 = input.nextDouble();
        System.out.print("Enter y1:");
        double y1 = input.nextDouble();

        System.out.print("Enter x2:");
        double x2 = input.nextDouble();
        System.out.print("Enter y2:");
        double y2 = input.nextDouble();

        double distance = Math.pow(Math.pow(x2-x1,2)+(y2-y1), 0.5);
        System.out.println("The distance between your points is "+distance);


        System.out.print("Do you want to continue? ");
        a = input.next();
    }while(a == "y");
}

}

0 个答案:

没有答案