java程式結構

來源:互聯網
上載者:User

標籤:運行   5*   str   print   比較   倒三角   void   mat   col   

if:

//        boolean i = true;//        if (i == true) {//            System.out.println("執行if了");//        }else{//            System.out.println("執行else了");//        }

switch:

//        int i = 30;//        switch(i){//        case 30://            System.out.println("你真傻");//            break;//        case 40://            System.out.println("你比較傻");//            break;//        case 50://            System.out.println("你有點傻");//            break;//        case 60://            System.out.println("你正常");//            break;//        }

while:

//        int i = 1;//        int j = 10;//        while(i<j){//            System.out.println(i+"*"+j+"="+i*j);//            i++;//            j--;//        }

do   while:

//        do {//            System.out.println(i+"*"+j+"="+i*j);//            i++;//            j--;//        } while (i<j);//        for(i = 1;i<j;i++){//            System.out.println(i+"*"+j+"="+i*j);//            j--;//        }

正三角,倒三角:

int i ;        int j ;        for(i = 3;i>=-3;i--){            int a = Math.abs(i);//取絕對值            for(j = a;j>0;j--){                System.out.print("*");            }            System.out.println("");        }

運行結果:

***

**

*

*

**

***

九九乘法:

public class Test03 {    public static void main(String[] args) {        //九九乘法表        int i;        int j;        for(i = 1;i<=9;i++){            for(j = 1;j<=i;j++){                System.out.print(j+"*"+i+"="+i*j+"\t");            }            System.out.println();        }    }}

運行結果:

1*1=1
1*2=22*2=4
1*3=32*3=63*3=9
1*4=42*4=83*4=124*4=16
1*5=52*5=103*5=154*5=205*5=25
1*6=62*6=123*6=184*6=245*6=306*6=36
1*7=72*7=143*7=214*7=285*7=356*7=427*7=49
1*8=82*8=163*8=244*8=325*8=406*8=487*8=568*8=64
1*9=92*9=183*9=274*9=365*9=456*9=547*9=638*9=729*9=81

java程式結構

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.