[ 작업 환경 ]
Windows10
jdk-15
1. Age.java 소스 작성
//********************************************************************
// Age.java Java Foundations
//
// Demonstrates the use of an if statement.
//********************************************************************
import java.util.Scanner;
public class Age
{
//-----------------------------------------------------------------
// Reads the user's age and prints comments accordingly.
//-----------------------------------------------------------------
public static void main (String[] args)
{
final int MINOR = 21;
Scanner scan = new Scanner (System.in);
System.out.print ("Enter your age: ");
int age = scan.nextInt();
System.out.println ("You entered: " + age);
if (age == 0){
System.out.println ("It's impossible");
} else if (age < MINOR){
System.out.println ("Youth is a wonderful thing. Enjoy.");
} else {
System.out.println ("Fighting!");
}
}
}
2. 실행 예시
javac Age.java
java Age