프로그래머스 (Swift)/기초
[Day2-4] 홀짝 구분하기
은더기
2024. 1. 14. 13:47
문제


내 정답 코드
import Foundation
let a = Int(readLine()!)!
var num: String = a % 2 == 0 ? "\(a) is even" : "\(a) is odd"
print(num)
#
2로 나눈 나머지 값으로 짝, 홀을 구분하고 삼항 연산자를 통해 string값을 저장해주었다.
배운 기술
1. 삼항 연산자
https://developer.apple.com/documentation/swift/operator-declarations
Operator Declarations | Apple Developer Documentation
Work with prefix, postfix, and infix operators.
developer.apple.com