我对这个 Java 程序的逻辑有疑问。它应该进入第一个 if/else 语句,但它没有?

I have a question regarding the logic of this Java program. It should go into the first if/else statement, but it does not?

因为 31 > 8,所以应该进入第一个 if 语句,因为 31 < 100,所以它应该进入 else 语句并输出“hi”。然而这个程序的输出是“ther3”。我确实知道 System.out.print("ther3"); 在两个 if 语句之外,无论如何都会打印出来。但是为什么System.out.print("hi");没有打印出来。

public static void main(String[] args) {
    int x = 31;
    int y = 8;
    if (x > y) {
        if (x > 100) {
            System.out.print("Hello");
        }
    }
    else
        System.out.print("hi");
    System.out.print("ther3");
}

它没有打印“hi”的原因是因为 else 部分属于 outer if 语句而不是 inner.
您可以看到外部 if 语句的花括号 {}。它先于其他关闭。这就是它没有被执行的原因。您可以更改它并查看一次输出。

if (x > y) {
   if (x > 100) { 
      System.out.print("Hello"); 
   } 
}
else
   System.out.print("hi");
System.out.print("ther3");