import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Calculator { public static void main(String[] args) { System.out.println("请输入数字和运算符"); BufferedReader bufferedReader = new BufferedReader( new InputStreamReader(System.in)); String num = null; int sum = 0; try { num = bufferedReader.readLine(); while (!num.equals("bye")) { for (int i = 0; i < num.length(); i++) { if (Character.toString(num.charAt(i)).equals("+")) { sum = Integer.parseInt(num.substring(0, i)) + Integer.parseInt(num.substring(i + 1)); break; } else if (Character.toString(num.charAt(i)).equals("-")) { sum = Integer.parseInt(num.substring(0, i)) - Integer.parseInt(num.substring(i + 1)); break; } else if (Character.toString(num.charAt(i)).equals("*")) { sum = Integer.parseInt(num.substring(0, i)) * Integer.parseInt(num.substring(i + 1)); break; } else if (Character.toString(num.charAt(i)).equals("/")) { sum = Integer.parseInt(num.substring(0, i)) / Integer.parseInt(num.substring(i + 1)); break; } } System.out.println(sum); num = bufferedReader.readLine(); } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }