Skip to content

Commit

Permalink
[ADD/#1] 코틀린 삼항연산자 실습
Browse files Browse the repository at this point in the history
  • Loading branch information
b1urrrr committed Nov 20, 2023
1 parent 4e3a5d3 commit 794430f
Showing 1 changed file with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ import java.util.Scanner
import kotlin.random.Random

fun main() {
// Random
practiceRandom()
practiceKeyboardInput()
practiceConditionalExpression()
}

private fun practiceRandom() {
var randomNumber = Random.nextInt()
print(randomNumber)

Expand All @@ -13,16 +18,18 @@ fun main() {

val randomDouble = Random.nextDouble(0.0, 1.0) // 0.0 ~ 0.9999...
print(randomDouble)
}

// 키보드 입력
private fun practiceKeyboardInput() {
val reader = Scanner(System.`in`)

val numberInput = reader.nextInt()
println(numberInput)
val stringInput = reader.next()
println(stringInput)
}

// 조건문
private fun practiceConditionalExpression() {
val i = 5
if (i > 10) {
print("10보다 크다")
Expand All @@ -38,4 +45,7 @@ fun main() {
else -> "!!!"
}
println(result)

val booleanResult = if (i > 10) true else false
println(booleanResult)
}

0 comments on commit 794430f

Please sign in to comment.