在控制台输入字母然后在控制台打印相应的二位数组字母,要求一行打印
1 package MyHomeWork; 2 3 import java.util.HashMap; 4 import java.util.Map; 5 import java.util.Scanner; 6 7 /** 8 * Created by zhouyubin on 7/11/14. 9 */ 10 public class Test2 { 11 private static final char[][] print_a={{' ',' ',' ','A',' ',' ',' ',' '}, 12 {' ',' ','A',' ','A',' ',' ',' '}, 13 {' ','A','A','A','A','A',' ',' '}, 14 {'A',' ',' ',' ',' ',' ','A',' '}, 15 {'A',' ',' ',' ',' ',' ','A',' '}}; 16 private static final char[][] print_b={{'B','B','B','B','B','B',' ',' '}, 17 {'B',' ',' ',' ',' ',' ','B',' '}, 18 {'B','B','B','B','B','B','B',' '}, 19 {'B',' ',' ',' ',' ',' ','B',' '}, 20 {'B','B','B','B','B','B',' ',' '}}; 21 private static final char[][] print_c={{' ','C','C','C','C','C','C',' '}, 22 {'C',' ',' ',' ',' ',' ',' ',' '}, 23 {'C',' ',' ',' ',' ',' ',' ',' '}, 24 {'C',' ',' ',' ',' ',' ',' ',' '}, 25 {' ','C','C','C','C','C','C',' '}}; 26 private static final char[][] print_d={{'D','D','D','D','D',' ',' ',' '}, 27 {'D',' ',' ',' ',' ',' ','D',' '}, 28 {'D',' ',' ',' ',' ',' ','D',' '}, 29 {'D',' ',' ',' ',' ',' ','D',' '}, 30 {'D','D','D','D','D',' ',' ',' '}}; 31 private static final char[][] print_e={{'E','E','E','E','E','E','E',' '}, 32 {'E',' ',' ',' ',' ',' ',' ',' '}, 33 {'E','E','E','E','E','E','E',' '}, 34 {'E',' ',' ',' ',' ',' ',' ',' '}, 35 {'E','E','E','E','E','E','E',' '}}; 36 private static final char[][] print_f={{'F','F','F','F','F','F','F',' '}, 37 {'F',' ',' ',' ',' ',' ',' ',' '}, 38 {'F','F','F','F','F','F','F',' '}, 39 {'F',' ',' ',' ',' ',' ',' ',' '}, 40 {'F',' ',' ',' ',' ',' ',' ',' '}}; 41 private static final char[][] print_g={{'G','G','G','G','G','G','G',' '}, 42 {'G',' ',' ',' ',' ',' ',' ',' '}, 43 {'G',' ',' ',' ',' ','G',' ',' '}, 44 {'G','G','G','G','G','G','G',' '}, 45 {' ',' ',' ',' ',' ','G','G',' '}}; 46 private static final char[][] print_h={{'H',' ',' ',' ',' ',' ','H',' '}, 47 {'H',' ',' ',' ',' ',' ','H',' '}, 48 {'H','H','H','H','H','H','H',' '}, 49 {'H',' ',' ',' ',' ',' ','H',' '}, 50 {'H',' ',' ',' ',' ',' ','H',' '}}; 51 private static final char[][] print_i={{' ',' ',' ','I',' ',' ',' ',' '}, 52 {' ',' ',' ','I',' ',' ',' ',' '}, 53 {' ',' ',' ','I',' ',' ',' ',' '}, 54 {' ',' ',' ','I',' ',' ',' ',' '}, 55 {' ',' ',' ','I',' ',' ',' ',' '}}; 56 private static final char[][] print_j={{' ','J','J','J','J',' ',' ',' '}, 57 {' ',' ',' ','J',' ',' ',' ',' '}, 58 {' ',' ',' ','J',' ',' ',' ',' '}, 59 {' ',' ',' ','J',' ',' ',' ',' '}, 60 {'J','J','J','J',' ',' ',' ',' '}}; 61 private static final char[][] print_k={{' ',' ',' ','K',' ','K',' ',' '}, 62 {' ',' ',' ','K','K',' ',' ',' '}, 63 {' ',' ',' ','K',' ',' ',' ',' '}, 64 {' ',' ',' ','K','K',' ',' ',' '}, 65 {' ',' ',' ','K',' ','K',' ',' '}}; 66 private static final char[][] print_l={{' ',' ',' ','L',' ',' ',' ',' '}, 67 {' ',' ',' ','L',' ',' ',' ',' '}, 68 {' ',' ',' ','L',' ',' ',' ',' '}, 69 {' ',' ',' ','L',' ',' ',' ',' '}, 70 {' ',' ',' ','L','L','L','L',' '}}; 71 private static final char[][] print_m={{' ',' ','M',' ',' ','M',' ',' '}, 72 {' ',' ',' ','M','M',' ',' ',' '}, 73 {' ','M',' ','M','M',' ','M',' '}, 74 {' ','M',' ','M','M',' ','M',' '}, 75 {' ','M',' ','M','M',' ','M',' '}}; 76 private static final char[][] print_n={{'N',' ',' ',' ',' ','N','N',' '}, 77 {'N',' ',' ',' ','N',' ','N',' '}, 78 {'N',' ',' ','N',' ',' ','N',' '}, 79 {'N',' ','N',' ',' ',' ','N',' '}, 80 {'N','N',' ',' ',' ',' ','N',' '}}; 81 private static final char[][] print_o={{' ','O','O','O','O','O',' ',' '}, 82 {'O',' ',' ',' ',' ',' ','O',' '}, 83 {'O',' ',' ',' ',' ',' ','O',' '}, 84 {'O',' ',' ',' ',' ',' ','O',' '}, 85 {' ','O','O','o','O','O',' ',' '}}; 86 private static final char[][] print_p={{'P','P','P','P','P','P',' ',' '}, 87 {'P',' ',' ',' ',' ',' ','P',' '}, 88 {'P','P','P','P','P','P',' ',' '}, 89 {'P',' ',' ',' ',' ',' ',' ',' '}, 90 {'P',' ',' ',' ',' ',' ',' ',' '}}; 91 private static final char[][] print_q={{' ','Q','Q','Q','Q','Q',' ',' '}, 92 {'Q',' ',' ',' ',' ',' ','Q',' '}, 93 {'Q',' ',' ',' ','Q',' ','Q',' '}, 94 {' ','Q','Q','Q','Q','Q',' ',' '}, 95 {' ',' ',' ',' ',' ',' ','Q',' '}}; 96 private static final char[][] print_r={{'R','R','R','R','R','R','R',' '}, 97 {'R',' ',' ',' ',' ',' ','R',' '}, 98 {'R','R','R','R','R','R','R',' '}, 99 {'R',' ','R','R',' ',' ',' ',' '}, 100 {'R',' ',' ',' ','R','R','R',' '}}; 101 private static final char[][] print_s={{' ','S','S','S','S','S','S',' '}, 102 {'S',' ',' ',' ',' ',' ',' ',' '}, 103 {' ','S','S','S','S','S',' ',' '}, 104 {' ',' ',' ',' ',' ',' ','S',' '}, 105 {'S','S','S','S','S','S',' ',' '}}; 106 private static final char[][] print_t={{'T','T','T','T','T','T','T',' '}, 107 {' ',' ',' ','T',' ',' ',' ',' '}, 108 {' ',' ',' ','T',' ',' ',' ',' '}, 109 {' ',' ',' ','T',' ',' ',' ',' '}, 110 {' ',' ',' ','T',' ',' ',' ',' '}}; 111 private static final char[][] print_u={{'U',' ',' ',' ',' ',' ','U',' '}, 112 {'U',' ',' ',' ',' ',' ','U',' '}, 113 {'U',' ',' ',' ',' ',' ','U',' '}, 114 {'U',' ',' ',' ',' ',' ','U',' '}, 115 {' ','U','U','U','U','U',' ',' '}}; 116 private static final char[][] print_v={{'V',' ',' ',' ',' ',' ','V',' '}, 117 {'V',' ',' ',' ',' ',' ','V',' '}, 118 {' ','V',' ',' ',' ','V',' ',' '}, 119 {' ',' ','V',' ','V',' ',' ',' '}, 120 {' ',' ',' ','V',' ',' ',' ',' '}}; 121 private static final char[][] print_w={{'W',' ',' ',' ',' ',' ','W',' '}, 122 {'W',' ',' ','W',' ',' ','W',' '}, 123 {' ','W',' ','W',' ','W',' ',' '}, 124 {' ',' ',' ','W',' ',' ',' ',' '}, 125 {' ',' ','W',' ','W',' ',' ',' '}}; 126 private static final char[][] print_x={{'X',' ',' ',' ',' ',' ','X',' '}, 127 {'X','X',' ',' ',' ','X','X',' '}, 128 {' ',' ','X','X','X',' ',' ',' '}, 129 {'X','X',' ',' ',' ','X','X',' '}, 130 {'X',' ',' ',' ',' ',' ','X',' '}}; 131 private static final char[][] print_y={{'Y',' ',' ',' ',' ',' ','Y',' '}, 132 {'Y',' ',' ',' ',' ',' ','Y',' '}, 133 {' ','Y',' ',' ',' ','Y',' ',' '}, 134 {' ',' ','Y','Y','Y',' ',' ',' '}, 135 {' ',' ',' ','Y',' ',' ',' ',' '}}; 136 private static final char[][] print_z={{'Z','Z','Z','Z','Z','Z','Z',' '}, 137 {' ',' ',' ',' ','Z',' ',' ',' '}, 138 {' ',' ',' ','Z',' ',' ',' ',' '}, 139 {' ','Z','Z',' ',' ',' ',' ',' '}, 140 {'Z','Z','Z','Z','Z','Z','Z',' '}}; 141 142 143 144 private static final Map<Character, char[][]> dict = new HashMap<Character, char[][]>(); 145 static{ 146 dict.put('a', print_a); 147 dict.put('b', print_b); 148 dict.put('c', print_c); 149 dict.put('d', print_d); 150 dict.put('e',print_e); 151 dict.put('f',print_f); 152 dict.put('g', print_g); 153 dict.put('h', print_h); 154 dict.put('i',print_i); 155 dict.put('j',print_j); 156 dict.put('k', print_k); 157 dict.put('l', print_l); 158 dict.put('m', print_m); 159 dict.put('n', print_n); 160 dict.put('o',print_o); 161 dict.put('p',print_p); 162 dict.put('q', print_q); 163 dict.put('r', print_r); 164 dict.put('s',print_s); 165 dict.put('t',print_t); 166 dict.put('u', print_u); 167 dict.put('v', print_v); 168 dict.put('w',print_w); 169 dict.put('x',print_x); 170 dict.put('y', print_y); 171 dict.put('z', print_z); 172 } 173 174 private static void print_str(char [][] ary) 175 { 176 for(int i=0;i<ary.length;i++){ 177 for(int j=0;j<ary[i].length;j++) 178 { 179 System.out.print(ary[i][j]); 180 } 181 System.out.println(); 182 } 183 } 184 private static void fill(char[][] led, char[][] word, int begin) { 185 for (int i = 0; i < word.length; i++) { 186 for (int j = 0; j < word[i].length; j++) { 187 led[i][j + begin] = word[i][j]; 188 } 189 } 190 } 191 192 public static void main(String[] args) { 193 Scanner scan=new Scanner(System.in); 194 System.out.println("Please input :"); 195 String word=scan.nextLine(); 196 word = word.replaceAll("[^a-zA-Z]",""); 197 word = word.toLowerCase(); 198 char[] wordCharAry = word.toCharArray(); 199 char[][] led = new char[5][wordCharAry.length * 8]; 200 for (int i = 0; i < wordCharAry.length; i++) { 201 int begin = i * 8; 202 fill(led, dict.get(wordCharAry[i]), begin); 203 } 204 print_str(led); 205 } 206 207 }