为什么条件判断总是跳出

IF条件判断中,总是无法将Scanner输入的字符串与“YES”进行比较,结果总是执行System.exit(0);个人无法解决,请有经验的Coder来帮忙看看。

import java.util.*;
import java.lang.Math;

public class TestPoint{
public static void main(String[] args){

System.out.println("please enter the x,y,z of a point:");
Scanner inX = new Scanner(System.in);
double inputX = inX.nextDouble();
Scanner inY = new Scanner(System.in);
double inputY = inX.nextDouble();
Scanner inZ = new Scanner(System.in);
double inputZ = inX.nextDouble();

System.out.println("the point you just have inputed is : x = " + inputX + ", y = " + inputY + ", z = " + inputZ);

Point p1 = new Point(inputX, inputY, inputZ);

System.out.println("the distance is :" + p1.getDistance(p1));
System.out.println("do you wanna change the value of x, y, z, do you? ");
[b]Scanner in = new Scanner(System.in);
String inIf = in.next();
String YES = "YES";

if(inIf == YES){[/b]
Scanner chX = new Scanner(System.in);
double changeX = chX.nextDouble();

Scanner chY = new Scanner(System.in);
double changeY = chY.nextDouble();

Scanner chZ = new Scanner(System.in);
double changeZ = chZ.nextDouble();

p1.modifyPoint(changeX, changeY, changeZ);
System.out.println("the distance after modified is :" + p1.getDistance(p1));
}
else{
System.exit(0);
}

}
}

class Point{
Point(double x, double y, double z){
this.x = x;
this.y = y;
this.z = z;
}

public void modifyPoint(double _x ,double _y ,double _z){
x = _x;
y = _y;
z = _z;
}


public double getDistance(Point point){
result = Math.sqrt(point.x * point.x + point.y * point.y + point.z * point.z);
return result;
}

private double result;
private double x;
private double y;
private double z;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值