(不好意思小宣傳一下我的繪圖 希望大家喜歡)

 

\\

這是我的海苔貓粉專

www.facebook.com/norinekocat/

 

海苔貓IG

海苔貓Instagram

 

謝謝大家:))

裡面有許多繪圖作品~ 

希望大家支持我會繼續努力

請多多指教哦


 

 

【最新Java 8程式語言 第四版 -練習題解答】第五章 流程控制(一):條件分支

選擇題

5.

(a)

import java.util.*;

public class first6 {

public static void main(String args[]) {

   int a,b;

   System.out.print("請輸入a");

   Scanner sc = new Scanner(System.in); // 為輸入資料加上的程式

   a = sc.nextInt();  // 將輸入資料轉成整數

   System.out.print("請輸入b");

   b = sc.nextInt();

 

   if (a>b)     

      System.out.println( "a="+ (a=b));

   

   else

      System.out.println( "b="+( b=a));                    

  }}

(b)

import java.util.*;

public class first6 {

public static void main(String args[]) {

   int a,b,c;

 

    System.out.print("請輸入a");

    Scanner sc = new Scanner(System.in); // 為輸入資料加上的程式

 

     a = sc.nextInt();  // 將輸入資料轉成整數

    System.out.print("請輸入b");

     b = sc.nextInt();

    System.out.print("請輸入c");

     c = sc.nextInt();

 

    if ((a>b)&&(a<c))     

      System.out.println( "a="+ (a=b+c));

   

   else

      System.out.println( "c="+( a-b));}}

計算題

2.

import java.util.*;

public class first5a2{

 

  public static void main (String [] argv){

 

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

 

 Scanner sc = new Scanner(System.in);

  int liter = sc.nextInt();

 

 

  if ((liter>=0)&&(liter<60)) {

     System.out.println("E");

  }

  else if ((liter>=60)&&(liter<70)) {

     System.out.println("D");

  }

  else if ((liter>=70)&&(liter<80)) {

     System.out.println("C");

  }

  else if ((liter>=80)&&(liter<90)) {

     System.out.println("B");

  }

 

  else if ((liter>=90)&&(liter<=100)) {

     System.out.println("A");

  }

}

}

 

3.

import java.util.*;

 

public class first5a3 {

 

  public static void main(String[] argv) {

 

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

 

    Scanner sc = new Scanner(System.in);

    int A = sc.nextInt();

 

    switch(A/10) {

       case 10: 

       case 9:  

        System.out.println("A");

        break;

      case 8:  

        System.out.println("B");

        break;

      case 7:  

        System.out.println("C");

        break;

      case 6:  

        System.out.println("D");

        break;

      default: // 其它狀況

        System.out.println("E");

    }

  }}

 

 

6.

 

import java.util.*; // 為輸入資料加上的程式

 

public class first5a6 {

 

  public static void main(String[] argv) {

    int i;

    i = 2088;

 

    System.out.print("請輸入密碼:");

 

    Scanner sc = new Scanner(System.in); // 為輸入資料加上的程式

    int liter = sc.nextInt();  // 將輸入資料轉成整數

 

    if (liter == 2088) { // 條件 1

      // 敘述 1

      System.out.println("密碼正確");

    }

    else  {

      // 敘述 2

      System.out.println("密碼錯誤");

    }

   

    }

  

}

 

7.

 

import java.util.*;

public class first5a7 {

public static void main(String[] argv) {

 

    System.out.print("請輸入通話時間:");

 

    Scanner sc = new Scanner(System.in);

    int liter = sc.nextInt();

 

    switch(liter/800) {     

       case 0:  //

        System.out.println(liter*9/10 +"");

        break;

      case 1:  //

        System.out.println((liter*9/10)*9/10 +"");

        break;

      default:  //

        System.out.println(liter*9/10*79/100 +"");

       

  

 

    }

  }

}

 

 

 

 

 

 

 

 

 

 

10.

 

import java.util.*;  

public class first5a10{

  public static void main (String [] argv){

     System.out.print("薪水算法?");

Scanner sc = new Scanner(System.in); //未輸入資料加上的程式

int hour = sc.nextInt();//取得整數

 

switch((hour-1)/60)

{

 case 0:

     System.out.println("以固定薪水計算\n");          //60小時以下

     break;

 case 1:

     System.out.println("以固定時薪的1.33倍計算\n");  //61~120小時

     break;

 case 2:

     System.out.println("以固定時薪的1.66倍計算\n");  //121小時以上

     break;

default:

     System.out.println("輸入錯誤\n");

     break; 

 }

}

}

 

 

 


 

ps

p新的貼圖終於出來了💜💜💜

可愛的海苔貓-第三代

 

海苔貓繪圖作品\\

 

 

希望大家支持~~

 

海苔貓粉專

海苔貓IG

 

 

arrow
arrow
    文章標籤
    Java 解答
    全站熱搜

    海苔貓Nori 發表在 痞客邦 留言(0) 人氣()