코딩테스트
[programmers] JAVA_0단계 홀짝 구분하기
congs
2024. 6. 11. 22:50
홀짝 구분하기
풀이
import java.util.Scanner;
public class Solution {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
System.out.print(n + " is "+(n % 2 == 0 ? "even" : "odd"));
//if(n%2==0){
// System.out.println(n + " is even");
//}
//else{
// System.out.println(n + " is odd");
// }
}
}
- 삼항연산자 : (조건)? true일경우 표현식 : false일경우 표현식