• 四则运算


    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();
            }
        }
    
    }
  • 相关阅读:
    第05组 Alpha冲刺 (6/6)
    第05组 Alpha冲刺 (5/6)
    第五次作业
    第05组 Alpha冲刺 (4/6)
    第05组 Alpha冲刺 (3/6)
    第05组 Alpha冲刺 (2/6)
    第05组 Alpha冲刺 (1/6)
    第四次作业
    差分约束
    置换群的性质与burnside引理
  • 原文地址:https://www.cnblogs.com/zbq0325/p/4556126.html
Copyright © 2020-2023  润新知