1.多重选择语句
package com.kuang.scanner;
import java.util.Scanner;
public class Demo04 {
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>=80){
System.out.println("优秀");
}else if (score<80&&score>=60){
System.out.println("很不错了");
}else if (score<60){
System.out.println("糟糕透了");
}else{
System.out.println("输入不合法");
}
scanner.close();
}
}
2.jdk1.7后支持字符串的选择
package com.kuang.scanner;
public class SwithCase {
public static void main(String[] args) {
String name="李四";
switch (name){
case "李四":
System.out.println("李四");
break;
case "王五":
System.out.println("王五");
break;
default:
System.out.println("你想输出啥");
}
}
}
3.Switch选择结构
package com.kuang.scanner;
public class Switch {
public static void main(String[] args) {
char grade='A';
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;
default:
System.out.println("啥也不是");
}
}
}
while循环
package com.kuang.scanner;
public class WhileDemo01 {
public static void main(String[] args) {
int i=0;
int sum=0;
while (i<=100){
sum=sum+i;
i++;
}
System.out.println(sum);
}
}
4.do while至少执行一次
package com.kuang.scanner;
public class WhileDemo01 {
public static void main(String[] args) {
int i=0;
int sum=0;
do {
sum=sum+i;
i++;
}
while (i<=100);
System.out.println(sum);
}
}