So I'm writing this program that simulates a coinflip with sides H and T, and its come time to create my method. The main idea behind the program is that a user should be able to enter any number b/w 1 and 511. Once the number is entered, my method should convert their number to binary, 0's being Heads, and 1's being Tails.
So if the user enters, 3, my methos should convert to 000000011, and then I want to convert it to print a matrix that looks like:
HHH
HHH
HTT
Here is my code so far, however my method (binaryConverter) is empty.I really have no clue where to begin.
import java.util.Scanner;
public class Problem8_11 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter one number between 0 and 511: ");
int number = input.nextInt();
String binaryValue = binaryConverter(number);
int[][] matrix = new int[3][3];
int binary = 0;
for (int i = 0; i < matrix.length; i++) {
for (int x = 0; x < matrix[i].length; x++) {
int HeadOrTails = (binaryValue.charAt(binary++) == '0') ? 0 : 1;
matrix[x][i] = HeadOrTails;
}
}
for (int i = 0; i < matrix.length; i++) {
for (int x = 0; x < matrix[i].length; x++) {
char HorT = (matrix[i][x] == 0) ? 'H' : 'T';
System.out.print(HorT + "");
}
System.out.println(" ");
}
}