- ★★Java質問・相談スレッド169★★
890 :デフォルトの名無しさん[]:2014/07/30(水) 09:47:11.47 ID:r+13Nr2E - class Point{
static double x,y; public void Point(){ this.x=0.0; this.y=0.0; } public double distance(Point that){ double xdiff = this.x-that.x; double ydiff = this.y-that.y; return Math.sqrt(xdiff*xdiff+ydiff*ydiff); } } class PointSample{ public static void main(String[] args){ Point lowerLeft = new Point(); Point upperRight = new Point(); lowerLeft.x = 0.0; lowerLeft.y = 0.0; upperRight.x=1280.0; upperRight.y=1024.0; double d = lowerLeft.distance(upperRight); System.out.println("Distance = " + d); } } dが0.0になっちゃうんだけどちゃんと出力するにはどうすりゃええんや
|