HW7.11

时间:2021-02-10 02:45:30

HW7.11

HW7.11

 import java.util.Scanner;

 public class Solution
 {
     public static void main(String[] args)
     {
         Scanner input = new Scanner(System.in);
         System.out.print("Enter a number between 0 and 511: ");
         int number = input.nextInt();

         input.close();

         char[] chArray = Integer.toBinaryString(number).toCharArray();
         char[][] displayArray = new char[3][3];

         for(int i = 0; i < 3; i++)
         {
             for(int j = 0; j < 3; j++)
             {
                 displayArray[i][j] = chArray[i * 3 + 1];
                 if(displayArray[i][j] == '0')
                     System.out.print('H' + " ");
                 else
                     System.out.print('T' + " ");
             }
             System.out.println();
         }
     }
 }

相关文章