<style>/* CSS的註解方式和Java,定義h1的風格 */

  h1{border: green solid 10px; padding: 20px; background-color: purple; color: orange; text-align: center;}

</style>

<h1>Java程式碼</h1>

<pre>

/*劉任昌2022/10/17w3Schools學雙迴圈,運算子operator,運算元operand*/

public class Main {

  public static void main(String[] args) {

    int i, j; /*宣告整數integer變數i, j*/

    String a="第", b="列:"; /*宣告整數字串a, b給初始值*/

    for ( i = 0; i < 8; i++) { /*迴圈*/

       System.out.print(a + i + b);/*+運算子用在字串,串接功能*/

       for ( j = 0; j <= i; j++)/*迴圈內僅有一道指令,可以不加{...}*/

          System.out.print(j); /*print輸出完,下一個print在後面,*/

       System.out.println(); /*println輸出完換列line,()空的,只有換列*/

    }

    }  

  }

}

</pre>

留言

張貼留言

這個網誌中的熱門文章

陳冠辰類別class __init__(self, 其他參數) 6月 05, 2023