流程控制
1.顺序结构
2.选择结构
a.算法结构很重要
b.比如100个数字里查找,if 分1-50;50-100,快速查找
eg
package basic;
import java.util.Scanner;
public class a7if {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("请输入字符");
String a = input.nextLine();
if (a.equals("你好")) {
System.out.println("你好");
} else {
System.out.println("你说啥");
}
System.out.println("请输入成绩");
float b=input.nextFloat();
if(b>100){
System.out.println("不是成绩");
}
else if(b>=90){
System.out.println("成绩优秀");
}else if(b>=80){
System.out.println("成绩较好");
}
else if(b>=70){
System.out.println("良");
}
else if(b>=60){
System.out.println("及格");
}
else{
System.out.println("输入不是成绩");
}
input.close();
}
}
package basic;
import java.util.Scanner;
public class a8switch {
public static void main(String[] args) {
//case 穿透,//switch匹配一个具体的结果
Scanner input=new Scanner(System.in);
System.out.println("请输入等级");
char a=input.next().charAt(0);
switch(a){
case ('A'):
System.out.println("优秀");
break;
case ('B'):
System.out.println("良");
break;
case ('C'):
System.out.println("及格");
break;
default:
System.out.println("等级不对");
}
}
}
标签:Scanner,DAY4,System,else,println,input,out From: https://www.cnblogs.com/vicxiao/p/16910830.html