Java学习第三天
public class If{
public static void main(String[] agrs){
SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。int score=40;
if (score==40){ //单行判断,如果是正确的,则输出值,否则,不会输出值(里面没有else)
System.out.println("答案正确");
}
}
}
public class If{
public static void main(String[] agrs){
int score=40;
if (score==40){ //多行判断,如果是正确的,则输出值,否则,输出另一个里面的值
System.out.println("答案正确");
}else{
System.out.println("答案错误");
}
}
}
import java.util.Scanner; //java 导入Scanner包
public class If{
public static void main(String[] agrs){
System.out.println("请输入分数:");
Scanner sc = new Scanner(System.in); //从键盘获取数据
int score = sc.nextInt(); //将数据赋值到函数里面
if(scorc>100||score<0){
System.out,println("您输入的分数有误,请重新输入!"); //给输入的数字限制到0到100里面
}else{ //这个属于嵌套语句 里面的属于多重循环语句
if(score>=80&&score<=100){
System.out.println("A");
}else if(score>=70&&score<80){
System.out.println("B");
}else if(score>=60&&socre<70){
System.out.println("C");
}else {
System.out.println("D");
}
}
}
}
