All pastes #987624 Raw Edit

Unbenannt

public text v1 · immutable
·published 2008-04-16 17:47 UTC
rendered paste body
import java.util.Scanner;
public class Calculator{

    public static void main (String args[]) {

        Scanner s = new Scanner(System.in);

        boolean error = false;
        int a = 0;
        int b = 0;
        char operator;
        int sum = 0;
        

        if ( s.hasNextInt()) {
            a = s.nextInt();
        }else{
            error=true;
        }

        if ( s.hasNextInt()) {
            b = s.nextInt();
        }else{
            error=true;
        }

        if (s.hasNext())
        {
            operator =s.next().charAt(0);

            if (operator  == '+'){
                sum = a + b;
            }

            else if (operator  == '-'){
                sum = a - b;
            }

            else if (operator  == '*'){
                sum = a * b;
            }

            else if (operator  == '/'){
                sum = a / b;
            }
            else error = true;
        }else{
            error = true;
        }

        if (error){
            System.out.println("FALSCHE EINGABE");
        }else{
            System.out.println(sum);
        }
    }
}