浏览 2389 次
锁定老帖子 主题:为什么条件判断总是跳出
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2014-08-28
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? "); Scanner in = new Scanner(System.in); String inIf = in.next(); String YES = "YES"; if(inIf == YES){ 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; } 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |
发表时间:2014-08-28
if(inIf == YES){ 改成 if(YES.equals(inIf))
|
|
返回顶楼 | |
发表时间:2014-08-28
ssunny 写道 if(inIf == YES){ 改成 if(YES.equals(inIf)) 解决了,回去看书。。。谢谢您了! |
|
返回顶楼 | |
发表时间:2014-09-01
equals
|
|
返回顶楼 | |