顯示廣告
隱藏 ✕
看板 Programming
作者 Leon (Leon)
標題 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 
1樓 時間: 2014-12-15 13:36:20 (美國)
  12-15 13:36 US
double distance(x1, x2, y1, y2){
2樓 時間: 2014-12-15 13:37:00 (美國)
  12-15 13:37 US
double x = x1-x2;
3樓 時間: 2014-12-15 13:37:15 (美國)
  12-15 13:37 US
double y = y1-y2;
4樓 時間: 2014-12-15 13:38:07 (美國)
  12-15 13:38 US
return sumSquares(x, y);
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!)
r)回覆 e)編輯 d)刪除 M)收藏 ^x)轉錄 同主題: =)首篇 [)上篇 ])下篇
看板名稱: 確定(Enter) 取消(Esc) 搜尋(Space)
查詢帳號: 確定(Enter) 取消(Esc) 搜尋(Space)
搜尋: m)m文 b)進板 c)未分類 a)作者 /)標題 q)取消?[q]

搜尋 送出(Enter) 取消(Esc)

回覆文章至: f)看板 m)作者信箱 b)兩者皆是 q)取消?[f]
要引用原文嗎? y)引用原文 n)不引用 a)全部回覆 r)複製原文 q)取消?[y]
轉錄本文章於看板: 1)使用連結 2)使用複製 q)取消 ?[1]
轉寄至站內信箱於使用者: 確定(Enter) 取消(Esc)
轉寄至站內信箱於使用者: 確定(Enter) 取消(Esc)
修改文章標題為: 確定(Enter) 取消(Esc)
修改文章標題為: 確定(Enter) 取消(Esc) 全部(a)

確定要刪除這篇文章?(可按大U救回) 確定(Enter) 取消(Esc)

刪除理由:

確定(Enter) 取消(Esc)
加到這個分類: 確定(Enter) 下一層(→) 回上層(←) 取消(Esc)
你覺得這篇文章: 1)真讚 2)真瞎 q)取消?[1] (再選一次即可收回)
你覺得這篇文章: 1)值得推薦 2)表示反對 3)單純註解 q)取消?[3]
guest
預覽(Enter) 取消(Esc)
上傳圖片
按ctrl+Enter可輸入下一行。
guest
確定要送出? 確定(Enter) 取消(Esc) 繼續(e)
搜尋: 送出(Enter) 取消(Esc)

▏▎▍▌▋▊▉ 請按任意鍵繼續