1. 程式人生 > 其它 >java流程控制之順序結構

java流程控制之順序結構

package struct;


import java.util.Scanner;

public class Demo01 {
    final  static Scanner scanner = new Scanner(System.in);
    public static void main(String[] args) {
        text();

        text2();

        text3();

        text4();

        text5();
    }
    /*
    順序結構
     */
    public static void text() {
        System.out.println("hello1");
        System.out.println("hello2");
        System.out.println("hello3");
        System.out.println("hello4");
        System.out.println("hello5");
    }

    /*
    選擇結構
     */

    public  static  void  text2(){

        System.out.println("請輸入內容:");
        String line = scanner.nextLine();

        if (line.equals("hello")){
            System.out.println(line);
        }else {
            System.out.println("error");
        }
//        scanner.close();
    }

    public  static  void  text3(){

        System.out.println("請輸入成績:");

        int score = scanner.nextInt();
        if (score>60){
            System.out.println("成績及格");
        }else {
            System.out.println("成績不及格");
        }
//        scanner.close();
    }


    public  static  void  text4(){
        System.out.println("請輸入你的成績:");
        int nextInt = scanner.nextInt();

        if (nextInt>=90){
            System.out.println("你的成績為:"+nextInt+"\t等級為:優秀");
        }else  if (nextInt>=80){
            System.out.println("你的成績為:"+nextInt+"\t等級為:良好");
        }else  if (nextInt>=70){
            System.out.println("你的成績為:"+nextInt+"\t等級為:中等");
        }else  if (nextInt>=60){
            System.out.println("你的成績為:"+nextInt+"\t等級為:及格");
        }else {
            System.out.println("你的成績為:"+nextInt+"\t等級為:不及格");
        }

//        scanner.close();
    }


    public  static  void  text5(){
        System.out.println("請輸入你的成績:");
        int nextInt = scanner.nextInt();

        if (nextInt==100){
            System.out.println("你的成績為:"+nextInt+"\t恭喜滿分");
        }else  if (nextInt<100&&nextInt>=90){
            System.out.println("你的成績為:"+nextInt+"\t等級為:A");
        }else  if (nextInt<90&&nextInt>=80){
            System.out.println("你的成績為:"+nextInt+"\t等級為:B");
        }else  if (nextInt<80&&nextInt>=70){
            System.out.println("你的成績為:"+nextInt+"\t等級為:C");
        }else  if (nextInt<70&&nextInt>=60){
            System.out.println("你的成績為:"+nextInt+"\t等級為:D");
        }else  if (nextInt<60&&nextInt>=0){
            System.out.println("你的成績為:"+nextInt+"\t等級為:不及格");
        }else {
            System.out.println("你輸入的成績不合法");
        }

        scanner.close();
    }
}