kotlin > 연산자 간단한 질문 있습니다.
조회수 441회
가장 작은 수를 출력하는 간단한 코드입니다.
import java.util.*
fun main() {
while(true) {
var smallNumber: Int = 101
print("Enter Number :") //string으로 받아오기
val sc: Scanner = Scanner(System.`in`)
val inputValue = sc.nextInt()
if(inputValue < 0){
break
}
# 이부분에서 < 연산자가 동작을 안함
smallNumber = if (inputValue < smallNumber) inputValue else smallNumber
var currentMin : (Int) -> Unit = {
number -> println("current min is $number")
}
gochaFunc(currentMin, smallNumber)
}
}
fun gochaFunc(function: (Int) -> (Unit), number: Int){
function(number)
}
Enter Number :50
50
current min is 50
Enter Number :52
52
current min is 52
smallNumber가 더 작은수를 가려내는게 아니라 들어오는 모든수로 대치 됩니다. 혹시 문법적으로 잘못한부분이 있나요?
댓글 입력