java HW 10.4
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了java HW 10.4相关的知识,希望对你有一定的参考价值。
import java.util.HashMap;
import java.util.Map;
public class MyASCII {
private Map<Character, String[]> ascii = new HashMap<>();
public MyASCII() {
super();
fillTheMap();
}
private void fillTheMap() {
Character keyA = 'a';
String[] valueA = {
" * ",
" * * ",
" * * ",
" ******* ",
" * * ",
"* * "};
ascii.put(keyA, valueA);
Character keyB = 'b';
String[] valueB = {
"******** ",
"* * ",
"******** ",
"* * ",
"* * ",
"******** "};
ascii.put(keyB, valueB);
Character keyC = 'c';
String[] valueC = {
" ******** ",
" * * ",
"* ",
"* ",
" * * ",
" ******** "};
ascii.put(keyC, valueC);
Character keyD = 'd';
String[] valueD = {
"******** ",
"* * ",
"* * ",
"* * ",
"* * ",
"******** "};
ascii.put(keyD, valueD);
Character keyE = 'e';
String[] valueE = {
"********* ",
"* ",
"****** ",
"* ",
"* ",
"********* "};
ascii.put(keyE, valueE);
Character keyF = 'f';
String[] valueF = {
"********* ",
"* ",
"******* ",
"* ",
"* ",
"* "};
ascii.put(keyF, valueF);
Character keyG = 'g';
String[] valueG = {
" ******** ",
" * * ",
"* ",
"* ****** ",
" * * ",
" ******** "};
ascii.put(keyG, valueG);
Character keyH = 'h';
String[] valueH = {
"* * ",
"* * ",
"********* ",
"* * ",
"* * ",
"* * "};
ascii.put(keyH, valueH);
Character keyI = 'i';
String[] valueI = {
"***** ",
" * ",
" * ",
" * ",
" * ",
"***** "};
ascii.put(keyI, valueI);
Character keyJ = 'j';
String[] valueJ = {
" ***** ",
" * ",
" * ",
" * ",
"* * ",
" **** "};
ascii.put(keyJ, valueJ);
Character keyK = 'k';
String[] valueK = {
"* * ",
"* * ",
"* * ",
"*** ",
"* * ",
"* ** "};
ascii.put(keyK, valueK);
Character keyL = 'l';
String[] valueL = {
"*** ",
" * ",
" * ",
" * ",
" * * ",
" ******** "};
ascii.put(keyL, valueL);
Character keyM = 'm';
String[] valueM = {
"* * ",
"* * * * ",
"* * * * ",
"* * * ",
"* * ",
"* * "};
ascii.put(keyM, valueM);
Character keyN = 'n';
String[] valueN = {
"* * ",
"* * * ",
"* * * ",
"* * * ",
"* * * ",
"* * "};
ascii.put(keyN, valueN);
Character keyO = 'o';
String[] valueO = {
" ***** ",
" * * ",
"* * ",
"* * ",
" * * ",
" ***** "};
ascii.put(keyO, valueO);
Character keyP = 'p';
String[] valueP = {
"******** ",
"* * ",
"* * ",
"******** ",
"* ",
"* "};
ascii.put(keyP, valueP);
Character keyQ = 'q';
String[] valueQ = {
" ***** ",
" * * ",
"* * ",
"* * * ",
" * * ",
" ***** * "};
ascii.put(keyQ, valueQ);
Character keyR = 'r';
String[] valueR = {
"******** ",
"* * ",
"* * ",
"******** ",
"* * ",
"* ** "};
ascii.put(keyR, valueR);
Character keyS = 's';
String[] valueS = {
" ****** ",
" * ",
" ****** ",
" * ",
" * ",
" ****** "};
ascii.put(keyS, valueS);
Character keyT = 't';
String[] valueT = {
"*********** ",
" * ",
" * ",
" * ",
" * ",
" * "};
ascii.put(keyT, valueT);
Character keyU = 'u';
String[] valueU = {
"* * ",
"* * ",
"* * ",
"* * ",
" * * ",
" ***** "};
ascii.put(keyU, valueU);
Character keyV = 'v';
String[] valueV = {
"* * ",
" * * ",
" * * ",
" * * ",
" * * ",
" * "};
ascii.put(keyV, valueV);
Character keyW = 'w';
String[] valueW = {
"* * ",
" * * * * ",
" * * * * ",
" * * * ",
" * * * * ",
" * * "};
ascii.put(keyW, valueW);
Character keyX = 'x';
String[] valueX = {
"* * ",
" * * ",
" * * ",
" * ",
" * * ",
"* * "};
ascii.put(keyX, valueX);
Character keyY = 'y';
String[] valueY = {
"* * ",
" * * ",
" * * ",
" * ",
" * ",
" * "};
ascii.put(keyY, valueY);
Character keyZ = 'z';
String[] valueZ = {
"********** ",
" * ",
" * ",
" * ",
" * ",
"********** "};
ascii.put(keyZ, valueZ);
Character key1 = '!';
String[] value1 = {
" ** ",
" ** ",
" ** ",
" ** ",
" ",
" ** "};
ascii.put(key1, value1);
Character key0 = ' ';
String[] value0 = {
" ",
" ",
" ",
" ",
" ",
" "};
ascii.put(key0, value0);
}
public void printAscii(String text) {
text.toLowerCase();
char[] chars = text.toCharArray();
for(int i = 0; i < 6; i++) {
String line = "";
for(int j = 0; j < chars.length; j++) {
line += (ascii.get(chars[j])[i]);
}
System.out.println(line);
}
}
}
public class Main {
public static void main(String[] args) {
// TODO Auto-generated method stub
MyASCII ascii = new MyASCII();
ascii.printAscii("hello world!");
System.out.println("");
System.out.println("");
ascii.printAscii("java is cool!!!");
System.out.println("");
System.out.println("");
ascii.printAscii("abcdefghijklmnopqrstuvwxyz");
}
}
以上是关于java HW 10.4的主要内容,如果未能解决你的问题,请参考以下文章