국비지원 JAVA 풀스택 과정/JAVA

[JAVA] 10대를 구별하는 프로그램 작성

ODaram 2022. 9. 23. 22:24

 삼항 연산자를 사용하여 10대를 구별하는 프로그램을 작성

  - 19세는 10대 입니다. 또는 19세는 10대가 아닙니다.

public class EEEEE {
	public static void main(String[] args){
		int age = 19;
		String str;
		str = (age>=10 && age<20) ? "10대 입니다." : "10대가 아닙니다." ;
		
		boolean result = age > 20;
		System.out.println(age+"살은"+str);
		
	}
}