判断语句1—if
格式
if(关系表达式) {
语句体;
}
public class Test {
public static void main(String[] args) {
int a = 1;
int b = 1;
if (a == b) {
System.out.println("ok");
}
}
}
判断语句2—if…else
格式
if(关系表达式) {
语句体1;
} else {
语句体2;
}
public class Test {
public static void main(String[] args) {
int a = 1;
int b = 1;
if (a == b) {
System.out.println("true");
} else {
System.out.println("false");
}
}
}
判断语句2—if…else if…else
格式
if(关系表达式) {
语句体1;
} else if (关系表达式) {
语句体2;
} else if (关系表达式) {
语句体3;
} else {
语句体;
}
public class Test {
public static void main(String[] args) {
int a = 1;
int b = 1;
int c = 1;
if (a == b) {
System.out.println("true");
} else if (b == c ) {
System.out.println("ture");
} else {
System.out.println("false");
}
}
}