if单选择结构
package com.bit.struct;
import java.util.Scanner;
public class IfDemo01 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("请输入内容");
String s = scanner.nextLine();
//equals判断字符串是否相等
if (s.equals("hello")){
System.out.println(s);
}
System.out.println("End");
scanner.close();
}
}
if双选择结构
package com.bit.struct;
import java.util.Scanner;
public class IfDemo02 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("请输入成绩 :");
int score = scanner.nextInt();
if (score>=60){
System.out.println("及格");
}else
{
System.out.println("不及格");
}
scanner.close();
}
}
if多选择结构
package com.bit.struct;
import java.util.Scanner;
public class IfDemo03 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("请输入成绩 ");
int s = scanner.nextInt();
if (s==100){
System.out.println("恭喜满分!");
}else if (s<100 && s>=90){
System.out.println("A级");
}else if (s<90 && s>=80){
System.out.println("B级");
}else if (s<80 && s>=70){
System.out.println("C级");
}else if (s<70 && s>=60){
System.out.println("D级");
}else if (s<60 && s>=0){
System.out.println("成绩不及格");
}
else{
System.out.println("成绩不合法");
}
scanner.close();
}
}