JWorld@TW the best professional Java site in Taiwan
      註冊 | 登入 | 全文檢索 | 排行榜  

» JWorld@TW » Java 新手區  

按列印兼容模式列印這個話題 列印話題    把這個話題寄給朋友 寄給朋友    訂閱主題
reply to topicthreaded modego to previous topicgo to next topic
本主題所含的標籤
作者 請問有關連續輸入Buffer問題
heyipomoea





發文: 40
積分: 0
於 2013-04-03 21:55 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
各位大大好

小弟在練習這個題目



程式碼如下
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
package Practice;
import java.io.*;
 
public class P3_31Nine {
  public static void main(String[] args) throws Exception {
    BufferedReader keyin = new BufferedReader(new InputStreamReader(System.in));
    System.out.println("請輸入A系數: ");    
    int Acoefficient = Integer.parseInt(keyin.readLine());    
    System.out.println("請輸入B系數: ");
    int Bcoefficient = Integer.parseInt(keyin.readLine());        
    System.out.println("請輸入C系數: ");
    int Ccoefficient = Integer.parseInt(keyin.readLine());    
    
    System.out.println("二元方程式是:"+Acoefficient+"X^2+"+Bcoefficient+"X+("+Ccoefficient+")=0");
    int discriminant = Bcoefficient^2 - (4*Acoefficient*Ccoefficient);
    System.out.println(discriminant);    
  }
}


但是當我輸入A=1 B=3 C=(-5)時

B平方減4AC 應該會等於 9-4*(-5)=29
但是輸出確是21...
但是我看我的Code logic應該都對阿
不知道問題出在哪裡
可以煩請大大幫我指正嗎?
謝謝^^"


heyipomoea edited on 2013-04-03 22:00
reply to postreply to post
作者 Re:請問有關連續輸入Buffer問題 [Re:heyipomoea]
chuanchu





發文: 120
積分: 0
於 2013-04-03 23:28 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
怎會使用位元運算
建議就是去買本書看一段時間,不懂就先找書。


reply to postreply to post
作者 Re:請問有關連續輸入Buffer問題 [Re:chuanchu]
heyipomoea





發文: 40
積分: 0
於 2013-04-04 16:33 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
我這個程式還沒寫完...
是寫到一半發現有Bug所以停下來...

煩問C大 "為什麼用位元運算?"的意思是??

感謝


reply to postreply to post
作者 Re:請問有關連續輸入Buffer問題 [Re:heyipomoea]
boss760130





發文: 7
積分: 1
於 2013-04-05 16:44 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
Bcoefficient^2 中的 '^' 是邏輯條件運算子的xor

xor互斥運算,當前後兩個運算元的值不相同時,才會輸出ture。

例如:a ^ b 等價於 ((a && !b) || (!a && b))。

次方可以用 Math.pow(double base, double exponent)

回傳以參數 base 為底, exponent 為次方的指數。 ^^


reply to postreply to post
作者 Re:請問有關連續輸入Buffer問題 [Re:boss760130]
heyipomoea





發文: 40
積分: 0
於 2013-04-06 20:33 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
謝謝boss, 給我那麼詳細的解說, 真的很感謝你。

reply to postreply to post
» JWorld@TW »  Java 新手區

reply to topicthreaded modego to previous topicgo to next topic
  已讀文章
  新的文章
  被刪除的文章
Jump to the top of page

JWorld@TW 本站商標資訊

Powered by Powerful JuteForum® Version Jute 1.5.8