728x90
문제
https://www.acmicpc.net/problem/9498
9498번: 시험 성적
시험 점수를 입력받아 90 ~ 100점은 A, 80 ~ 89점은 B, 70 ~ 79점은 C, 60 ~ 69점은 D, 나머지 점수는 F를 출력하는 프로그램을 작성하시오.
www.acmicpc.net
코드
시험 점수를 입력받아 점수별 등급을 출력하는 문제다.
- A : 90 ~ 100
- B : 80 ~ 89
- C : 70 ~ 79
- D : 60 ~ 69
- F : 59 이하
if 문 사용
fun main() {
val input = readln().toInt()
if (input >= 90) {
println("A")
} else if (input >= 80) {
println("B")
} else if (input >= 70) {
println("C")
} else if (input >= 60) {
println("D")
} else {
println("F")
}
}
when 문 사용
fun main() {
val input = readln().toInt()
when {
input >= 90 -> println("A")
input >= 80 -> println("B")
input >= 70 -> println("C")
input >= 60 -> println("D")
else -> println("F")
}
}
728x90