day03-流程控制语句-判断流程-if格式一

This commit is contained in:
2026-01-14 15:55:24 +08:00
parent 2c20b05374
commit e35b8e5933

View File

@@ -0,0 +1,43 @@
package com.inmind.if01;
/*
if格式一
if(判断条件){
语句;
}
执行顺序:先执行判断条件,判断条件必须是布尔型的结果,
如果为true就执行大括号内部的语句false就直接跳过大括号中的内容
*/
public class Demo01 {
public static void main(String[] args) {
//请大家使用if格式一打印出哪个整数变量大
int a = 10;
int b = 20;
if(a > b){
System.out.println("变量a的值大"+a);
}
if(b > a){
System.out.println("变量b的值大"+b);
}
System.out.println("程序结束");
}
//抽取为一个if的格式一的方法
public static void ifMethod1() {
int i = 100;
//如果i的值大于10我就打印一次helloworld如果不满足条件则不打印
if(i > 10){
System.out.println("helloworld");
}
System.out.println("程序结束");
}
}