- package site.istak.org.tw;
- import java.util.Scanner;
- public class Main {
-
- public static void main(String[] args){
- Scanner scanner =new Scanner(System .in);
- int x=scanner.nextInt();
- int y=scanner.nextInt();
- String c=scanner.next();
- Calc calc = new Calc(x,y,c);
- Calc.calc(x, y, c);
-
- }
- }
複製代碼- package site.istak.org.tw;
- public class Calc {
- private float num1;
- private float num2;
- private String oper;
-
- public Calc(float x,float y,String c){
- this.num1=x;
- this.num2=y;
- this.oper=c;
-
-
-
- }
- public static void calc(float x,float y,String c){
-
- switch(c)
- {
- case"+":
- System.out.println(x+y);
- break;
- case"-":
- System.out.println(x-y);
- break;
- case"*":
- System.out.println(x*y);
- break;
- case"/":
- System.out.println(x/y);
- break;
- }
-
-
- }
- }
複製代碼 |