Question

The goal of this problem is to practice using appropriate branching statements. You will add to the main method to take in us2 import java.util.Scanner; public class Clue{ public static void main(String[] args) { Scanner scnr = new Scanner(System.in)

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer:

Here is the code:

Explanation:

if else if else blocks are used . witness input is taken from the user using next() function from Scanner and is stored in a String variable. After that, equalsIgnoreCase function is used to compare the strings with the witness input.

import java.util.Scanner;
public class Clue
{
   public static void main(String[] args) {
       Scanner scnr = new Scanner(System.in);
       System.out.println("Who was the murderer?");
      
       String witness_input = scnr.next();
      
       if(witness_input.equalsIgnoreCase("Amos"))
       {
       System.out.println("It was Amos with the candlestick!");
       }
       else if(witness_input.equalsIgnoreCase("Kevin"))
       {
       System.out.println("It was Kevin with the revolver!");
       }
       else if(witness_input.equalsIgnoreCase("Juan"))
       {
       System.out.println("It was Juan with the lead pipe!");
       }
       else
       {
       System.out.println("We're not sure who that is. We need to investigate further.");
       }
   }
}

output:

Who was the murderer? amos It was Amos with the candlestick! ... Program finished with exit code 0 Press ENTER to exit consol

PLEASE UPVOTE IF YOU FOUND THIS HELPFUL!

Add a comment
Know the answer?
Add Answer to:
The goal of this problem is to practice using appropriate branching statements. You will add to...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT