위와 같은 구조를 만들어 순서대로 조건을 검사할 수 있다. 어떤 조건이 참이면, 그 부분의 내용을 실행하고 조건/선택 구조를 빠져나간다.
이렇게 조건들을 순서대로 검사할 때에는 중간에 범위가 빠지지 않았는지 꼼꼼하게 생각하고 조건들을 만드는 것이 중요하다. 이는 마치 수학에서 빠진 범위 없이 부등식을 만드는 것과 유사하다.
입력
정수(0 ~ 100) 1개가 입력된다.
출력
평가 결과를 출력한다.
입력 예시
73
출력 예시
B
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
if(a >= 90){
System.out.println("A");
} else if (a>=70){
System.out.println("B");
} else if (a>=40){
System.out.println("C");
} else {
System.out.println("D");
}
}
}