국비교육/국비교육 복습
Day03_data_Test18 : 논리 연산자 boolean
Luver Duck
2022. 7. 31. 16:20
(Q) 2000년생이 편의점에 와서 담배를 사려고 합니다.
구매 가능한지 판정해서 출력
(담배는 한국 나이로 20세 이상이면 구매가 가능합니다)
package day02;
import java.lang.*;
public class Day03_data_Test18 {
public static void main(String[] args) {
int now = 2022;
int birth = 2000;
int age = now - birth + 1;
boolean purchase = age >= 20;
System.out.println(purchase);
}
}
1) 한국은 태어날 때부터 1살이다
- 나이를 구할 때 now와 birth가 같은 경우(갓 태어날 떄) +1을 해야 한다
int age = now - birth + 1;