亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何用 Java 編寫乘法表?

如何用 Java 編寫乘法表?

繁花如伊 2023-06-21 14:46:57
我正在學習 Java,我得到的任務之一是編寫如下所示的乘法表: 1  2  3  4  5  6  7  8  9 10 // 1 2  4  6  8 10 12 14 16 18 20 // 2 3  6  9 12 15 18 21 24 27 30 // 3....我已經研究了兩天了,但我無法找到答案。我主要關心的是如何編寫一個代碼來執行乘法到 10 并返回到下一行的下一行。我已經測試了很多方法,例如下面的代碼,但存在問題,我不知道問題出在哪里。請幫我。int t = 1;while(t <= 10) {    int r = 1;    int a = 1;    int b = 1;    System.out.print(r + " ");    a = a + 1;    t++;}
查看完整描述

4 回答

?
BIG陽

TA貢獻1859條經驗 獲得超6個贊

像這樣的表可能最好使用 for 循環來完成:


for (int i = 1; i <= 10; i++) {

    for (int j = 1; j <= 10; j++) {

        System.out.print(i*j + " ");

    }

    System.out.println();

}

如果你還沒有學習for循環并且想使用while循環,你可以使用


int i = 1;

int j = 1;


while (i <= 10) {

    while (j <= 10) {

        System.out.print(i*j + " ");

        j = j + 1;

    }

    System.out.println();

    i = i + 1;

}


查看完整回答
反對 回復 2023-06-21
?
慕標琳琳

TA貢獻1830條經驗 獲得超9個贊

http://img1.sycdn.imooc.com//64929d070001fd1905780207.jpg

 public class HelloWorld{


     public static void main(String []args){

        System.out.println("Hello World");

        int count = 1;

do {

  for( int j = 1; j <= 10; j ++) {

System.out.print( count*j +""+'\t');}

            count++;

            System.out.print('\n');


}while (count<11);






     }

}


查看完整回答
反對 回復 2023-06-21
?
搖曳的薔薇

TA貢獻1793條經驗 獲得超6個贊

使用內部循環來循環內部


public  void multiacation(){

for(i = 1; i <= 10; i ++) {

  for(j = 1; i <= 10; i ++) {

System.out.println(i*j +"");}}

試試這個,然后告訴我它是否有效


查看完整回答
反對 回復 2023-06-21
?
忽然笑

TA貢獻1806條經驗 獲得超5個贊

嘗試兩個 for 循環。


for(i = 1; i <= 10; i ++) {

  for(j = 1; i <= 10; i ++) {

     System.out.print(i*j + " ");

  }

  System.out.println();

}


查看完整回答
反對 回復 2023-06-21
  • 4 回答
  • 0 關注
  • 195 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號