回覆列表
  • 1 # 半夏半心南巷花開

    importjava.util.Scanner;

    publicclassTest{

    publicstaticvoidmain(String[]args){

    Scannerscanner=newScanner(System.in);

    System.out.print("請輸入第一個數字:");

    doublefirst=scanner.nextDouble();

    System.out.print("請輸入運算子(+-*/%):");

    charoperator=scanner.next().charAt(0);

    System.out.print("請輸入第二個數字:");

    doublesecond=scanner.nextDouble();

    doubleresult=0D;

    switch(operator){

    case"+":

    result=first+second;

    break;

    case"-":

    result=first+second;

    break;

    case"*":

    result=first*second;

    break;

    case"/":

    result=first/second;

    break;

    case"%":

    result=first%second;

    break;

    default:

    result=first-second;

    break;

    }

    System.out.println(first+""+operator+second+"="+result);

    }

    }

    ----------testing

    請輸入第一個數字:10

    請輸入運算子(+-*/%):/

    請輸入第二個數字:2

    10.0/2.0=5.0

  • 中秋節和大豐收的關聯?
  • 江雪這首詩流露出詩人怎樣的心?