if
package com.m.demo;
import java.util.Scanner;
public class IfSwitchWhile2 {
public static void main(String[] args) {
Scanner s=new Scanner(System.in);
System.out.print("输入成绩");
double score=s.nextDouble();
// if(score<60.0) {
// System.out.println("不及格");
// }else {System.out.println("及格");
//
// }
// if(score>=90) {
// System.out.println("优秀");
// }else if(score>=75) {
// System.out.println("良好");
// }else {
// System.out.println("一般");
// }
}
}
switch
package com.m.demo;
import java.util.Scanner;
public class IfSwitchWhile3 {
public static void main(String[] args) {
System.out.println("输入名次");
Scanner s=new Scanner(System.in);
int index=s.nextInt();
switch(index) {
case 1:System.out.println("1");break;
case 2:System.out.println("2");break;
case 3:System.out.println("3");break;
default:System.out.println("0");break;
}
}
}
循环
while、dowhile、for
package com.m.demo;
import java.util.Scanner;
public class IfSwitchWhile {
public static void main(String[] args) {
int i=0,j=0;
// //while循环
// while(i<=100) {
// System.out.printf("循环了%d次\r\n",(j+1));
// j++;
// i+=10;
//
// }
do while
// do {
// System.out.printf("循环了%d次,i=%d\r\n",(j+1),i);
// j++;
// i+=10;
// }while(i<=100);
// for循环
for(;i<100;j++,i+=10) {
System.out.printf("循环了%d次,i=%d\r\n",(j+1),i);
}
}
}