In: Computer Science
1. 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.
import java.util.Scanner;
public class RedBalloon {
public static void main (String [] args) {
Scanner scnr = new
Scanner(System.in);
boolean isRed;
boolean isBalloon;
isRed = scnr.nextBoolean();
isBalloon = scnr.nextBoolean();
/* Your solution goes here */
}
}
2. Assign isTeenager with true if kidAge is 13 to 19 inclusive. Otherwise, assign isTeenager with false.
import java.util.Scanner;
public class TeenagerDetector {
public static void main (String [] args) {
Scanner scnr = new
Scanner(System.in);
boolean isTeenager;
int kidAge;
kidAge = scnr.nextInt();
/* Your solution goes here */
if (isTeenager) {
System.out.println("Teen");
}
else {
System.out.println("Not teen");
}
}
}
import java.util.Scanner; public class RedBalloon { public static void main (String [] args) { Scanner scnr = new Scanner(System.in); boolean isRed; boolean isBalloon; isRed = scnr.nextBoolean(); isBalloon = scnr.nextBoolean(); if(isBalloon && isRed){ System.out.println("Red balloon"); } else if(isBalloon){ System.out.println("Balloon"); } else { System.out.println("Not a balloon"); } } }
////////////////////////////////////////// import java.util.Scanner; public class TeenagerDetector { public static void main(String [] args){ Scanner scnr = new Scanner(System.in); boolean isTeenager; int kidAge; kidAge = scnr.nextInt(); if(kidAge>=13 && kidAge<=19){ isTeenager = true; } else { isTeenager = false; } if(isTeenager){ System.out.println("Teen"); } else{ System.out.println("Not teen"); } } }