Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Write a program that randomly generates a character H or T, which represents head or tail. The program then prompts the user to enter a
Write a program that randomly generates a character H or T, which represents head or tail. The program then prompts the user to enter a guess and reports whether the guess is correct or incorrect.
- In order to generate a random character, first generate a random number, 0 or 1, using the Math.random() method, and then use a selection block to map 0 to H and 1 to T.
- For reading a character from a user, first read a string using a Scanner instance and then take the first character using charAt() method.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started