看板 Programming
作者 標題 Re: 問一題JAVA的習題
時間 2014年07月10日 Thu. AM 07:34:05
※ 引述《Leon》之銘言:
: 小弟在自學JAVA中
: 教材是Think Java
: 目前在第六章習題6.5卡關
: 麻煩大家指點迷津^^
: Exercise 6.5.
: The distance between two points (x1, y1) and (x2, y2) is Distance = 根號((x2 � x1)^2 + (y2 � y1)^2)
: Write a method named distance that takes four doubles as parameters—x1, y1, x2 and y2—and that prints the distance between the points.
: You should assume that there is a method named sumSquares that calculates and returns the sum of the squares of its arguments. For example:
: double x = sumSquares(3.0, 4.0);
: would assign the value 25.0 to x.
: The point of this exercise is to write a new method that uses an existing one.
: You should write only one method: distance.
: You should not write sumSquares or main and you should not invoke distance.
: 搞不懂它到底要我怎麼做@@
自回
依題意它應該是要我寫個distance method(算兩座標點距),
裡面必須引用到一個假設的sumSquares method(算兩平方面積和),
而因為sumSquares只是假設的,故不需要main method實際去跑結果。
問題一、我的理解對嗎?
問題二、如果我的理解是對的,我卻想不出來如何在distance method裡面運用sumSquares,我想不出兩者的關係。@@
--
※ 作者: Leon 時間: 2014-07-10 07:34:05
※ 看板: Programming 文章推薦值: 0 目前人氣: 0 累積人氣: 1066
5樓 時間: 2014-12-15 13:40:35 (美國)
→
12-15 13:40 US
} method head should be: public static double distance(double x1, double x2, double y1, double x2){ (type too fast, sorry!)
回列表(←)
分享