通過函數從四個方向輸出九九乘法表__函數

來源:互聯網
上載者:User
package hhl; public class jiujiu { public static void main(String[] args) { zuoshang();//調用輸出左上乘法表的函數 zuoxia();//調用輸出左下乘法表的函數 youshang();//調用輸出右上乘法表的函數 youxia();/調用輸出右下乘法表的函數 } public static void zuoshang()//定義輸出左上乘法表的函數 { for(int i=1;i<=9;i++)//通過for語句的嵌套輸出九九乘法表 { for(int j=1;j<=i;j++) { System.out.print(j+”*”+i+”=”); System.out.printf(“%-4d”,i*j); } System.out.println(); } } public static void zuoxia()//定義輸出左下乘法表的函數 {{ System.out.println(); for(int i=9;i>=1;i–)//同上 { for(int j=1;j<=i;j++) { System.out.print(j+”*”+i+”=”); System.out.printf(“%-4d”,i*j); } System.out.println(); }} public static void youshang()//定義輸出右上乘法表的函數 {{ for(int i=1;i<=9;i++)//同上 { for(int j=i;j<9;j++) { System.out.print(“\t”); }    for(int j=i;j>0;j--)    {        if((i*j)<10)            System.out.print(" "+j+"*"+i+"="+(i*j)+"\t");        else            System.out.print(+j+"*"+i+"="+(i*j)+"\t");    }    System.out.println();}  System.out.println(); } public static void youxia()//定義輸出右下乘法表的函數 { { for(int i=9;i>0;i–)//同上 { for(int j=0;j<9-i;j++) { System.out.print(“\t”); }        for(int j=i;j>0;j--)        {            if((i*j)<10,                System.out.print(" "+j+"*"+i+"="+(i*j)+"\t");            else                System.out.print(+j+"*"+i+"="+(i*j)+"\t");        }        System.out.println();    }} }

運行結果如下:

本次實驗的知識點:
1,for迴圈語句與if語句的嵌套使用。在Java中定義函數和調用。
2,對九九乘法表這一類知識的掌握,以及各種輸出方法的嘗試 。
本次實驗的總結:
1,對函數在Java中使用的瞭解和掌握,
2,對對多重迴圈的運用讓程式更加簡潔易懂。
3,自生的不足,對於計算這一方面的思維不是很強,以及對軟體操作的不熟,望下次提高。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.