顺序结构和条件结构
知识点:
顺序结构:
选择结构:
if结构:
switch结构:
代码:
if结构:
public class ShunxuDemo {
public static void main(String[] args) {
Scanner scanner =new Scanner(System.in);
System.out.println("请输入内容:");
String s =scanner.nextLine();
//equals:判断字符串是否相等
if(s.equals("hello")){
System.out.println(s);
}
System.out.println("End");
scanner.close();
}
}
public class IfDemo {
public static void main(String[] args) {
//成绩大于60及格,小于60分不及格
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();
}
}
public class IfDemo02 {
public static void main(String[] args) {
Scanner scanner =new Scanner(System.in);
System.out.println("请输入成绩:");
int score =scanner.nextInt();
if(score==1000){
System.out.println("恭喜满分");
}
else if(score <100 && score>=90) {
System.out.println("优秀");
}
else if(score <90 && score>=70) {
System.out.println("良好");
}
else if(score <70 && score>=60) {
System.out.println("及格");
}
else if(score <60&&score>=0) {
System.out.println("不及格");
}
else {
System.out.println("成绩不合法");
}
scanner.close();
}
}
switc结构:
public class SwitchDemo01 {
//case 穿透 匹配一个具体的值
public static void main(String[] args) {
char grade ='F';
switch (grade){
case 'A':
System.out.println("优秀");
break; //可选
case 'B':
System.out.println("良好");
break;
case 'C':
System.out.println("及格");
break;
case 'D':
System.out.println("不及格");
break;
case 'E':
System.out.println("再来一年");
break;
default:
System.out.println("回家种地");
}
}
}
public class SwitchDemo02 {
public static void main(String[] args) {
/**
jdk的特性,表达式结果可以说字符串!!!
字符串的本质还是数字
*/
//反编译 java---class(字节码的文件)------反编译(IDEA)
String name ="伟哥";
switch (name){
case "梦祥" :
System.out.println("梦祥");
break;
case "祥哥" :
System.out.println("祥哥");
break;
default:
System.out.println("爬");
}
}
}
System.out.println("祥哥");
break;
default:
System.out.println("爬");
}
}
}