import java.util.*;
import java.lang.*;
import java.io.*;

// The main method must be in a class named "Main".
class Main {
    public static void main(String[] args) {
        //Dades
        Scanner tec = new Scanner(System.in);
        System.out.println("Introduce el primer valor:");
        double n1 = tec.nextDouble();
        System.out.println("Introduce el segundo valor valor:");
        double n2 = tec.nextDouble();
        System.out.println("Introduce el operador (+,-,*,/):");
        char o1 = tec.next().trim().charAt(0);//next LINE ESTUDIAR (en vez de trim)
        tec.close(); 
        //Calcul
        double r = 0;
        int ERROR = 0;
        switch (o1){
            case '+': r=n1+n2; break;
            case '-': r=n1-n2; break;
            case '*': r=n1*n2; break;
            case '/': r=n1/n2; break;
            default: ERROR = 1;
        }
        //Salida
        if (n2<0 && ERROR == 0){
        System.out.println (n1+" "+o1+" ("+n2+") = " +r);
        }
        else if (n2>=0 && ERROR == 0){
        System.out.println (n1+" "+o1+" "+n2+" = " +r);
        }
        else if (ERROR == 1){
        System.out.println ("Escibe un operador compatible");
        }
    }
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: