たしかめ

Run Settings
LanguageKotlin
Language Version
Run Command
/** * You can edit, run, and share this code. * play.kotlinlang.org */// data class MyDate(val year: Int, val month: Int, val dayOfMonth: Int) : Comparable<MyDate> { override fun compareTo(other: MyDate) = when { year != other.year -> year - other.year month != other.month -> month - other.month else -> dayOfMonth - other.dayOfMonth } } class DateRange(val start: MyDate, val endInclusive: MyDate) { operator fun contains(item: MyDate): Boolean = start <= item && item <= endInclusive } fun checkInRange(date: MyDate, first: MyDate, last: MyDate): Boolean { return date in DateRange(first, last) } fun HowToUse_in(){//inを使ってみる //in と contain を使ってみる val list = listOf("a","b") println(list) println( "a" in list) //aがリストに含まれているか? println( "a" !in list) println( list.contains("a")) println( !list.contains("a")) } fun main(args : Array<String>){ HowToUse_in() //-----checkInRangeを使ってみる //今日(2019年8月20日) var today = MyDate(2019,8,31) //去年の始めと終わり(戌年) val inu_FirstDay = MyDate(2018,1,1) val inu_LastDay = MyDate(2018,12,31) //今年の初めと終わり(亥年) val inosisi_FirstDay = MyDate(2019,1,1) val inosisi_LastDay = MyDate(2019,12,31) println("今日は戌年か? ${checkInRange(date=today,first=inu_FirstDay,last=inu_LastDay)}") println("今日は亥年か? ${checkInRange(date=today,first=inosisi_FirstDay,last=inosisi_LastDay)}") //-----checkInRangeを使ってみる }
Editor Settings
Theme
Key bindings
Full width
Lines