Help us understand the problem. What is going on with this article?

kotlinで簡単な曜日検索

More than 3 years have passed since last update.

月と日にちを入力したらその曜日を出力する簡単なもの

karender.kt
import java.util.Scanner

fun main(args: Array<String>) {
    val monlist = listOf(31,28,31,30,31,30,31,31,30,31,30,31)
    var t = 0
    val input = Scanner(System.`in`)
    println("月を入力(例 7)")
    var month : Int = input.nextInt()
    println("日を入力(例 23)")
    val day : Int = input.nextInt()
    month = month-1
    for(i in 1..month){
        t =  t + monlist[i-1]
    }
    val ans : Int = day + t
    when(ans % 7){
        1 -> println("日曜")
        2 -> println("月曜")
        3 -> println("火曜")
        4 -> println("水曜")
        5 -> println("木曜")
        6 -> println("金曜")
        0 -> println("土曜")
    }
}
実行結果
月を入力(例 7)
7
日を入力(例 23)
24
月曜

kotlinはjavaに比べて楽になった部分もあった(小並感)

nimani76
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away