public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
if (n % 2 == 0) {
System.out.printf("%d is even", n);
}
else System.out.printf("%d is odd", n);
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
System.out.print(n + " is ");
System.out.println(n%2 == 0 ? "even" : "odd");
}
이런 식으로도 가능
// 삼항 연산자
int A = (1 > 3) ? 10 : 30;
// 결과 A = 30;
'코테 공부 > java' 카테고리의 다른 글
Integer .valueOf(str) .parseInt(str) 차이 (0) | 2023.05.01 |
---|---|
str.substring() (0) | 2023.05.01 |
대소문자 변환 Character.isUpperCase(인자), str.toUpperCase(), Character.toUpperCase(인자) (0) | 2023.05.01 |
문자열 반복, x만큼 간격이 있는 n개의 숫자 (0) | 2023.04.30 |
Scanner (0) | 2023.04.30 |