引用 | 編輯
righer
2005-03-16 05:54 |
樓主
▼ |
||
x0
這是經過上次的程式碼小改了一下import javax.swing.JOptionPane; public class Welcome{ public static void main(String args[]) { String n1,n2; int f1,sum=0 ; n1=JOptionPane.showInputDialog("enter a num"); f1 = Integer.parseInt(n1); sum = f1; System.ou .. 訪客只能看到部份內容,免費 加入會員 x0
|
引用 | 編輯
Kuster
2005-03-16 08:37 |
1樓
▲ ▼ |
複製程式
import javax.swing.JOptionPane; public class Welcome{ public static void main(String args[]) { String n1,n2; int f1,sum=0,i; n1=JOptionPane.showInputDialog("enter a num"); f1 = Integer.parseInt(n1); sum = f1; for(i=1; i<=9; i++) System.out.println("answer = " + sum*i); } } 這樣就可以啦~~ x0 |
引用 | 編輯
GenuxMM
2005-03-16 09:25 |
2樓
▲ ▼ |
下面是引用righer於2005-03-16 05:54發表的 [求助]請教迴圈的的寫法:上面的大大這句還是拆兩行,比較容易看 for(i=1; i<=9; i++) System.out.println("answer = " + sum*i); 下面是我的版本 while(i<=9) System.out.println("answer=" + sum*(i++)); x0 |
引用 | 編輯
righer
2005-03-16 12:51 |
3樓
▲ ▼ |
恩 感謝大大的幫助 原來這就是迴圈 之前學C有碰過 不過不知道是幹什麼的
現在我想把這程式寫的更完美 想把原先的answer ex.answer=3 -> 3*1=3 answer=6 -> 3*2=6 這樣一直到9 我朋友提點我還要用一次迴圈 但是不知道從哪下手 x0 |
引用 | 編輯
Lex
2005-03-22 14:18 |
4樓
▲ |
下面是引用righer於2005-03-16 12:51發表的 : for (int i = 1; i >= 9; i++) { for (int J = 1;j >=9; j++) { int k = i*j; System.out.println("answer = " + k + " ->" + i + "*" + j + "=" + k); } } 會印出answer = 1 -> 1 * 1 = 1 到answer = 81> 9 * 9 = 81 大致架構是這樣~ 我沒去組譯過~你試試看~ 如果數字不對~改改數字就好~ x0 |