CHALLENGE ACTIVITY 2.11.2: Boolean in branching statements. 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. (Notes) 432564 2520080.qx3zqy7 1 import java.util.Scanner; 2 3 public class RedBalloon { 4 public static void main (String[] args) { 5 Scanner scnr = new Scanner(System.in); 6 boolean isRed; 7 boolean isBalloon; 8 9 isRed = scnr.nextBoolean(); 10 isBalloon = scnr.nextBoolean(); 11 12 } 13 } 14 } Run 1 test passed All tests passed
Added by Edward M.
Close
Step 1
First, we need to import the Scanner class to read input from the user. Show more…
Show all steps
Your feedback will help us improve your experience
Patricia Holmes and 98 other AP CS educators are ready to help you.
Ask a new question
Labs
Want to see this concept in action?
Explore this concept interactively to see how it behaves as you change inputs.
Key Concepts
Recommended Videos
Write an if-else statement with multiple branches: If givenYear is 2101 or greater, print "Distant future" (without quotes). Else, if givenYear is 2001 or greater (2001 - 2100), print "21st century". Else, if givenYear is 1901 or greater (1901-2000), print "20th century". Else (1900 or earlier), print "Long ago". Do NOT end with newline. import java.util.Scanner; public class YearChecker { public static void main (String[] args) { Scanner scnr = new Scanner(System.in); int givenYear; givenYear = scnr.nextInt(); // Your solution goes here * } }
Florencia C.
Write a switch statement that checks nextChoice. If 0, print "Rock". If 1, print "Paper". If 2, print "Scissors". For any other value, print "Unknown". End with newline. import java.util.Scanner; public class Roshambo { public static void main(String[] args) { Scanner scnr = new Scanner(System.in); int nextChoice; nextChoice = scnr.nextInt(); // Your solution goes here } }
Dadasaheb S.
Write an if-else statement for the following: If userTickets is equal to 7, execute awardPoints = 1. Else, execute awardPoints = userTickets. Ex: If userTickets is 3, then awardPoints = 3. import java.util.Scanner; public class TicketCounter { public static void main(String[] args) { int awardPoints; int userTickets; Scanner scnr = new Scanner(System.in); userTickets = scnr.nextInt(); // Program will be tested with values: 5, 6, 7, 8. /* Your code goes here */ System.out.println(awardPoints); } }
Akash M.
Recommended Textbooks
Computer Science and Information Technology
Introduction to Programming Using Python
Computer Science - An Overview
Watch the video solution with this free unlock.
EMAIL
PASSWORD