if else
程序员文章站
2024-01-07 11:31:58
...
if
public class IfDemo01 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("请输入内容:");
String s = scanner.nextLine();
//判断字符串内容是否相等
if(s.equals("hello")){
System.out.println("s = " + s);
}
System.out.println("end..");
scanner.close();
}
}
if else
public class IfDemo02 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("请输入成绩");
int i = scanner.nextInt();
if(i>60){
System.out.println("及格!");
}else {
System.out.println("不及格!");
}
scanner.close();
}
}
if 多重else if
public class IfDemo03 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("请输入成绩");
int i = scanner.nextInt();
if(i==100){
System.out.println("满分!");
}else if(i<100 && i>=80){
System.out.println("优秀!");
} else if(i<80 && i>=60){
System.out.println("及格!");
} else if(i<60){
System.out.println("不及格!");
} else {
System.out.println("成绩不合法!");
}
scanner.close();
}
}