[Swift] 입력 받기 readLine()

Zoe·2023년 4월 2일
0

🕊️ Swift

목록 보기
2/5
post-thumbnail

readLine() Apple Developer Documentation


정수(Int) 입력받기

let i = Int(readLine()!)!
print(i)

공백 단위로 입력받기 (정수)

let input1 = readLine()!.split(separator: " ").map { Int(String($0))! }
print(type(of: input1))
//Array<Int>

연속적인 입력 처리

let input = Array(readLine()!)
print(input)
print(type(of: input))

let result = input.map { Int(String($0))! }
print(result)
print(type(of: result))
profile
모른다는 말로 다가가 새로운 기술을 반갑게 맞이하고 적용하여 새로운 문제 해결을 꿈꿉니다.

0개의 댓글