if 文・switch 文と、Java 14以降のモダンな switch 式のコード例です。
public class BranchExample {
public static void main(String[] args) {
int score = 85;
// if文
if (score >= 90) {
System.out.println("A");
} else if (score >= 80) {
System.out.println("B");
} else {
System.out.println("C");
}
// モダンな switch 式 (Java 14+)
String grade = switch (score / 10) {
case 10, 9 -> "秀";
case 8 -> "優";
default -> "可";
};
}
}