1. 程式人生 > 其它 >java簡易計算器(無法累計計算,練手)

java簡易計算器(無法累計計算,練手)

package com.moneypine.method;

import java.util.Scanner;

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

//控制輸入條件及物件
System.out.println("輸入第一個數字");
double a = scanner.nextDouble();
System.out.println("選一個:+,-,*,/");
char b = scanner.next().charAt(0);
System.out.println("輸入第二個數字");
double c = scanner.nextDouble();

scanner.close();

//判斷輸入符號,呼叫加減乘除方法
switch (b) {
case '+':
double reslut_add = add(a,b,c);
System.out.println(reslut_add);
break;
case'-':
double result_minus = minus(a,b,c);
System.out.println(result_minus);
break;
case'*':
double result_mutiply = multiply(a,b,c);
System.out.println(result_mutiply);
break;
case'/':
double reslut_divide = divide(a,b,c);
System.out.println(reslut_divide);
break;

}
}
//包裝每一個方法類
public static double add(double a,char b,double c){
return a + c;
}
public static double minus(double a,char b,double c){
return a - c;
}
public static double multiply(double a,char b,double c){
return a * c;
}
public static double divide(double a,char b,double c){
return (a/c);
}
}