判断:
if假如
例1:
public class Test39 {
public static void main(String[] args) {
int a = 0;
if (a == 4) {
System.out.println(a);
}
if (a < 4) {
System.out.println("齐井");
System.out.println(a);
}
}
}
结果:
齐井
0
例2:
public class Test40 {
public static void main(String[] args) {
int i = 0;
if (i < 1) {
System.out.println("你好");
System.out.println(i);
i++;
}
if (i < 1) {
System.out.println("你好");
System.out.println(i);
i++;
}
}
}
结果:
你好
0
例3:
public class Test41 {
public static void main(String[] args) {
int i = 0;
if (i < 2) {
System.out.println("你好");
System.out.println(i);
i++;
}
if (i < 2) {
System.out.println("你好");
System.out.println(i);
i++;
}
if (i < 2) {
System.out.println("你好");
System.out.println(i);
i++;
}
}
}
结果:
你好
0
你好
1
例4:
public class Test {
public static void main(String[] args) {
String a="qijing";
if (a.equals("qijing")) {
System.out.println("qijing 的分数是95");
}else{
System.out.println("你不是qijing");
}
}
}
结果:
qijing 的分数是95
作业1:马克-to-win:让整数a=2,让b=3,假如a大于b将输出a。让a=4,假如a大于b就输出a
public class Test42 {
public static void main(String[] args) {
int a= 2;
int b= 3;
if (a >b) {
System.out.println(a);
}
a=4;
if (a > b) {
System.out.println(a);
}
}
}
结果:
4
作业2:马克-to-win:假如s="大明",赋值fenshu等于88打印分数,String s="小红"赋值fenshu=95,打印分数。
public class Test43 {
public static void main(String[] args) {
String s = "大明";
int fenshu;
if (s.equals("大明")) {
fenshu = 88;
System.out.println(fenshu);
}
if (s.equals("小红")) {
fenshu = 95;
System.out.println(fenshu);
}
}
}
结果:
88
作业3:马克-to-win:假如nianji==3,赋值kewai="音乐",打印kewai,假如ninianji==4,赋值kewai="太极"打印kewai
public class Test44 {
public static void main(String[] args) {
String kewai;
int nianji = 4;
if (nianji == 3) {
kewai = "音乐";
System.out.println(kewai);
}
if (nianji == 4) {
kewai = "太极";
System.out.println(kewai);
}
}
}
结果:
太极