2013年計(jì)算機(jī)軟考程序員教程

字號(hào):

流程控制語句(分支語句和循環(huán)語句)
     程序體驗(yàn):
    public class Test5 {
    /**
    * @param args
    * 分支語句的測(cè)試
    * 1路 if
    * 2路 if else
    * N路 switch case
    */
    public static void main(String[] args) {
    int [] scope={34,56,78,29,58,90,80};
    for (int i = 0; i < scope.length; i++) {
    if(scope[i]>=90){
    System.out.println("A");
    }else{
    if(scope[i]>80){
    System.out.println("B");
    }else{
    if(scope[i]>70){
    System.out.println("C");
    }else{
    -
    if(scope[i]>60){
    System.out.println("D");
    }else{
    System.out.println("不及格");
    }
    }
    }
    }
    }
    if(20<=scope[3] & scope[3]<=30);
    scope[3]=45;
    System.out.println(scope[3]);
    System.out.println("---------------------------------");
    /**
    * N路分支語句switch case
    * 1、break的有無 2、default的位置 3、改變default位置并去掉其break
    * 4、請(qǐng)問:switch中可以傳入什么類型的值?
    * byte short int char enum
    */
    for (int i = 0; i < scope.length; i++) {
    int temp=scope[i]/10;
    switch (temp) {
    default:
    System.out.print("不及格");
    System.out.print("哈哈,我是多余的..");
    // break;
    case 10:
    case 9:
    System.out.print("A");
    break;
    case 8:
    System.out.print("B");
    break;
    case 7:
    System.out.print("C");
    break;
    case 6:
    System.out.print("D");
    break;
    }
    }
    }