Re: [問題] java的問題

看板java作者時間19年前 (2007/03/18 02:01), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串1/1
※ 引述《roger70349.bbs@ptt.cc (roger70349)》之銘言: > 請各位大大能否幫我看一下下面的程式那裡有問題 > 寫一個applet程式,可計算M~N的總和(其中M,N為使用者自行輸入) > import javax.swing.JOptionPane; > public class MtoN > { > int sum=0; > int m,n; > public MtoN (int x) > { n=x; > for (int i=m;i<=n;i++) > { > sum=sum+i; > } > } > public static void main(String args[]) > { > String s = JOptionPane.showInputDialog("請輸入n值:"); > String s1= JOptionPane.showinputDialog("請輸入m值"); > int n=Integer.parseInt(s); > int m=Integer.parseInt(s1); > MtoN a=new Sum1toN(n); > MtoN a=new Sum1toN(m); > JOptionPane.showMessageDialog(null,a.n"1到"+a.m+"加總=" + a.sum,"加總 > ",JOptionPane.PLAIN_MESSAGE ); > } > } > 還有有題是請輸入一個十六進位整數, 將其轉換為 > (1) 二進位 (2)八進位 (3)十進位 輸出 這不算是Applet的程式,你比較一下下面的程式哪裡有差別,因為有很多地方要改 import javax.swing.JOptionPane; public class MtoN { int sum=0; int m,n; public MtoN(int m,int n) { for (int i=m;i<=n;i++) { sum=sum+i; } } public static void main(String args[]) { String s = JOptionPane.showInputDialog("請輸入m值:"); String s1= JOptionPane.showInputDialog("請輸入n值"); int m=Integer.parseInt(s); int n=Integer.parseInt(s1); MtoN a=new MtoN(m,n); JOptionPane.showMessageDialog(null,m+"到"+n+"的加總="+a.sum,"加總", JOptionPane.PLAIN_MESSAGE ); } } -- ┌─────KKCITY─────┐  找歌最方便 KKBOX 歌詞搜尋!! bbs.kkcity.com.tw \^_^ / http://www.kkbox.com.tw └──From:220.138.47.102 ──┘   唱片公司授權,音樂盡情下載 --
文章代碼(AID): #15_2pb00 (java)
文章代碼(AID): #15_2pb00 (java)