Write an ifelse statement to describe an object Print Balloo

Write an if-else statement to describe an object. Print \"Balloon\" if isBalloon is true and isRed is false. Print \"Red balloon\" if isBalloon and isRed are both true. Print \"Not a balloon\" otherwise. End with newline.

Solution

Please find the code and it\'s output below :


public class App1 {
   public static void main(String args[]) {
       // boolean variables
       boolean isBalloon = true, isRed = true;
       if (isBalloon && isRed) {
           System.out.println(\"Red balloon\");
       } else if (isBalloon && !isRed) {
           System.out.println(\"Balloon\");
       } else {
           System.out.println(\"Not a balloon\");
       }

   }
}

====O/P===

Red balloon

Write an if-else statement to describe an object. Print \

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site