if(number<10){...}
等价于
boolean b
b=number<10
if(b){...}
不明白的话继续问
if(条件){//具体逻辑
}
if 条件句,如果条件为真(即条件结果为true),那么就会执行具体逻辑。
这里直接写上if (true),是说条件必定满足,就是说执行条件句if里面的具体操作。
原因:没有加else
修改后代码:
public class Test {
public static void main(String[] args) {
/*if语句的第一种格式: if(条件表达式) { 执行语句; }*/
int x=1
if(x>1) {
System.out.println("Yes")//如果为真,则输出“Yes”
}
else {
System.out.println("over")
}
}
}
运行结果: