Answered step by step
Verified Expert Solution
Link Copied!

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.image text in transcribed
  • For reading a character from a user, first read a string using a Scanner instance and then take the first character using charAt() method.
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. Hints: 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. Sample run: Guess head or tail (H or T)? H Correct! You can read my mind. Another run: Guess head or tail (H or T)? H Sorry, it was tails

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional Visual Basic 6 Databases

Authors: Charles Williams

1st Edition

1861002025, 978-1861002020

Students also viewed these Databases questions

Question

How do Excel Pivot Tables handle data from non OLAP databases?

Answered: 1 week ago