2019年7月18日 星期四

switch 系列

01
               int score;
  System.out.println("請輸入成績");
  score = sc.nextInt();
  
  String flag;
  System.out.println("是否擔任幹部?Y/N");
  flag = sc.next();
  if(flag.equals("Y")||flag.equals("y")) {
   score=score+10;
  }
  
  System.out.println("是否曾得獎?Y/N");
  flag = sc.next();
  if(flag.equals("Y")||flag.equals("y")) {
   score=score+10;
  }
  
  System.out.println(score);
02
 int a = 10;
  int ans = (a >= 0) ? 0 : 1;

  System.out.println((ans > 0) ? 0 : 1);
  
  // 判斷成績------------------
  Scanner sc = new Scanner(System.in);
  System.out.println("...分數...");
  int score = sc.nextInt();

  if (score >= 0 && score <= 100) {   
   switch ((score>=60)?0:1) {   
   case 0:
    System.out.println("及格");
    break;
   case 1:
    System.out.println("不及格");
    break;
   }
  } else {
   System.out.println("不再範圍");
  }
 }

沒有留言:

張貼留言

Raspberry Pi 做 PostgreSQL(Timescale) 讓真實溫度資料寫入到PostgreSQL - PostgreSQL有GUI操作畫面

此次範例Raspberry Pi 4 先下載 樹梅派系統 軟體 先確定OK在做系統寫入 先更新系統 sudo apt update sudo apt upgrade -y 因為這次是要有GUI介面的(所以需要安裝Docker) Step 1 安裝 Docker sudo apt ...