java 语言 if else语句的使用方法

时间:2025-02-19 10:28:57

if  else语句的结果如下

if(条件1){
//代码块1
}else if(条件2){
//代码块2
}else{//代码块3}
if else语句使用方法:如果条件1是true则执行 代码块1,如果条件2是true则执行代码块2,否则执行代码块3。下面是例子:
public class test {
	public static void main(String[] args){
		Boolean  test =false;
		if(test ==false){
			("1The test is ture");
		}else {
			("1The test is false");
		}
		 test =true;
		if(test ==false){
			("2The test is ture");
		}else {
			("2The test is false");
		}
		
	}

例子的结果是:

1The test is ture
2The test is false