if
if单
if (br表达式){//如果br表达式为true将输出的
package ds;
import java.util.Scanner;
public class Dome4 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("请输入");
String s = scanner.nextLine();
//equals判断字符是否相等
if (s.equals("hello")) {//如果br表达式为true的话
System.out.println(s);//就会输出这个
}
System.out.println("end");
scanner.close();
}
}
if
if(br表达式){//如果br表达式为true就输出这行的
}else{
//如果br表达式为false就输出这行的
}
package ds;
import java.util.Scanner;
public class Dome5 {
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多
if(){
}else if () {
}else if () {
}else {
}
package ds;
import java.util.Scanner;
public class Dome6 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("请输入成绩:");
int score = scanner.nextInt();
if (score == 100) {
System.out.println("满分");
} else if(score<100 && score>=90){
System.out.println("A级");
}else if (score<90 && score >70){
System.out.println("B级");
}else if (score<70 && score>60){
System.out.println("C级");
}else if (score<60 && score>=0){
System.out.println("不及格");
}else {
System.out.println("成绩不合法");
}
scanner.close();
}
}