2019年5月21日 星期二

Kotlin學習筆記(19) 99乘法表

Kotlin學習筆記(19)  99乘法表

fun main(args : Array<String>){
    multiplication9x9Table()
}

fun multiplication(a: Int, b: Int) = a * b  //Kotlin新特性!!!!

fun multiplication9x9Table(){

    for(i in 0..9){
        if(i==0){
            //打印第一行
            for(i in 0..9){
                if(i==0)
                    print("*  ")
                else
                    print("$i  ")

            }
            println()
        } else {
            print("$i  ")  //打印第一列

            for(j in 1..i){ 
                //打印内容
                print(multiplication(i,j).toString()+"  ")
            }

            println()  //换行
        }
    }
}

輸出畫面
* 1 2 3 4 5 6 7 8 9 1 1 2 2 4 3 3 6 9 4 4 8 12 16 5 5 10 15 20 25 6 6 12 18 24 30 36 7 7 14 21 28 35 42 49 8 8 16 24 32 40 48 56 64 9 9 18 27 36 45 54 63 72 81

沒有留言:

張貼留言

2024產專班 作業2 (純模擬)

2024產專班 作業2  (純模擬) 1) LED ON,OFF,TIMER,FLASH 模擬 (switch 控制) 2)RFID卡號模擬 (buttom  模擬RFID UID(不從ESP32) Node-Red 程式 [{"id":"d8886...