码迷,mamicode.com
首页 > 编程语言 > 详细

JAVA的流程控制

时间:2020-11-10 11:21:45      阅读:11      评论:0      收藏:0      [点我收藏+]

标签:流程   obj   lin   efault   static   manage   output   def   lse   

1.流程控制:顺序结构,分支(判断)结构,循环结构。

  package com.langtao.scanner;

  import com.sun.deploy.security.SelectableSecurityManager;

  import java.sql.SQLOutput;
  import java.util.Scanner;

  public class Demo2 {
      public static void main(String[] args) {
          //New an object of Scanner to receive the input from Keyboard from the user.
          Scanner scanner = new Scanner(System.in);

          //String str = scanner.nextLine();
          //System.out.println(str);
          int m = 3;

          while(m>0){
              System.out.println("Please enter your score: ");

              if(scanner.hasNextInt()){
                  int score = scanner.nextInt();
                  System.out.println("Your score is: " + score);

                  switch (score/10){
                      case 10:
                          System.out.println("Excellent, full mark!");
                          break;
                      case 9:
                          System.out.println("Very good!");
                          break;
                      case 8:
                      case 7:
                          System.out.println("Not bad.");
                          break;
                      case 6:
                          System.out.println("Pass!");
                          break;
                      default:
                          System.out.println("Failed");

                  }
              }else{
                  System.out.println("Invalid entry, please enter your score.");
              }
              m--;
          }


          scanner.close();

      }
  }

JAVA的流程控制

标签:流程   obj   lin   efault   static   manage   output   def   lse   

原文地址:https://www.cnblogs.com/langtaoshuo/p/13951606.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!