Question: Nine coins are placed in a 3-by-3 matrix with some face up and some face down. You can represent the state of the coins using

Nine coins are placed in a 3-by-3 matrix with some face up and some face down. You can represent the state of the coins using a 3-by-3 matrix with values 0 (heads) and 1 (tails). Here are some examples:10 1 11 0 10 1 1 1 0 1 0 0

Each state can also be represented using a binary number. For example, the preceding matrices correspond to the numbers000010000 101001100 110100001 101110100 100111110There are a total of 512 possibilities, so you can use decimal numbers 0, 1, 2, 3, . . . , and 511 to represent all states of the matrix. Write a program that prompts the user to enter a number between 0 and 511 and displays the corresponding matrix with the characters H and T. Here is a sample run:10 0 0 1 0 1 0 0 1 11 1 1

The user entered 7, which corresponds to 000000111. Since 0 stands for H and 1 for T, the output is correct.

10 1 11 0 10 1 1 1 0 1 0 0 10 0 0 1 0 1 0 0 1 11 1 1 0 10 0 Enter a number between 0 and 511: 7 JEnter

Step by Step Solution

3.44 Rating (154 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Program Plan Import the required packages into the program Define the main function o Get the input from the user and display its corresponding matrix ... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Java Programming Questions!