SDUT- 1133 C/C++經典程式訓練3---模擬計算器
阿新 • • 發佈:2019-02-06
import java.util.Scanner; class Number { int a, b; String c; Number(int n, int m, String k) { a = n; b = m; c = k; } void Print() { int ans = 0; if(c.equals("+"))ans = a + b; else if(c.equals("-"))ans = a - b; else if(c.equals("*"))ans = a * b; else ans = a / b; System.out.println(ans); } } public class Main { public static void main(String[] args) { Scanner cin = new Scanner(System.in); int a, b; String c; a = cin.nextInt(); b = cin.nextInt(); c = cin.nextLine(); c = cin.nextLine(); Number p = new Number(a, b, c); p.Print(); cin.close(); } }