If-else One line statement (with string and integer) [closed]

your solution variable Type is int, and your else statement returns an String, this is the cause of error.

you can change your code to this:

Scanner input = new Scanner (System.in);
    int B = input.nextInt();
    int H = input.nextInt();
    int P;

    if (B >= 0 && H >= 0) {
        P = B*H;
    } else {
        throw new Exception("Breadth and height must be positive");


Browse More Popular Posts

Leave a Comment