if的单选择结构
public class ifDemo001 { public static void main(String[] args) { Scanner scanner= new Scanner(System.in); System.out.println("请输入您的成绩:"); int a= scanner.nextInt(); if(a<60){ System.out.println("不合格"); } } }
if的双选择结构
public class ifDemo002 { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.println("请输入您的成绩:"); int a= scanner.nextInt(); if(a<60){ System.out.println("不合格"); }else{ System.out.println("合格"); } } }
if的多选择结构
public class ifDemo002 { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.println("请输入您的成绩:"); int a= scanner.nextInt(); if(a<60&&a>=0){ System.out.println("不合格"); }else if(a>=60&&a<80){ System.out.println("合格"); }else if (a>=80&&a<90){ System.out.println("良好"); }else if (a>=0&&a<=100){ System.out.println("优秀"); }else{ System.out.println("输入不合法"); } } }
嵌套的if结构