if(布尔表达式){ //如果布尔表达式为true将执行的语句 }
public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.println("请输入内容:"); String s = scanner.nextLine(); if (s.equals("人类消灭暴政")){ System.out.println("世界属于三体!"); } }
public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.println("请输入内容:"); String s = scanner.nextLine(); if (s.equals("人类消灭暴政")){ System.out.println("世界属于三体!"); }else { System.out.println("回答错误"); } }
public static void main(String[] args) { while (true) { System.out.println("请输入您的成绩:"); Scanner scanner = new Scanner(System.in); int a = scanner.nextInt(); if (a >= 60) { System.out.println("成绩及格"); } else { System.out.println("成绩不及格"); } } }
public static void main(String[] args) { while (true){ System.out.println("请输入你的成绩:"); Scanner scanner = new Scanner(System.in); double a = scanner.nextDouble(); if (a == 100){ System.out.println("恭喜你获得了满分!"); }else if (a < 100 && a >= 90){ System.out.println("优秀"); }else if (a < 90 && a >=80){ System.out.println("良好"); }else if (a < 80 && a >=70){ System.out.println("良好"); }else if (a < 70 && a >=60){ System.out.println("良好"); }else if (a < 60 ){ System.out.println("不及格"); }else { System.out.println("请输入0-100之间的数:"); } } }