fun main() {
val age = 24
val layers = 5
printCakeCandles(age)
printCakeTop(age)
printCakeBottom(age, layers)
}
fun printCakeCandles(age: Int) {
print (" ")
repeat(age) {
print(",")
}
println() // Print an empty line
print(" ") // Print the inset of the candles on the cake
repeat(age) {
print("|")
}
println()
}
fun printCakeTop(age: Int) {
repeat(age + 2) {
print("=")
}
println()
}
fun printCakeBottom(age: Int, layers: Int) {
repeat(layers) {
repeat(age + 2) {
print("@")
}
println()
}
}
fun : 함수
main : 함수 이름(기본 함수)
val : 키워드, 뒤에 오는 것이 변수 이름
repeat() : 반복문(루프)
println : 출력
println("") or \n : 빈줄(줄바꿈)
${} : print 문 텍스트의 변수와 계산 값을 사용할 때
'Kotlin' 카테고리의 다른 글
[Kotlin] ? 물음표 / !! 느낌표 두개 (null 처리) (0) | 2021.09.15 |
---|---|
[Kotlin] copyOf, toArray, contentToString (배열 복사) (0) | 2021.09.10 |
[Kotlin] object (0) | 2021.09.10 |
[Kotlin] Property / Backing Field (0) | 2021.09.10 |
[Kotlin] 기본 문법 (0) | 2021.02.21 |