DEV Community

Dineth Shan Gimhana
Dineth Shan Gimhana

Posted on

How Can I replace throw exception with a System.out.print() in switch statement default case

Here I have a simple class to perform calculator operations.

Calculator.java

    private final ArrayList <Double> values
    private final String operation;

    public Calculator(ArrayList<Double> values, String operation) {
        this.values = values;
        this.operation = operation;
    }

    public double calculate(){
        double num1 = values.get(0);
        double num2 = values.get(1);
        double answer;

        switch (operation) {
            case

Top comments (0)