-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathyourName.java
More file actions
64 lines (58 loc) · 1.97 KB
/
yourName.java
File metadata and controls
64 lines (58 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package practice;
import javax.print.DocFlavor;
import java.util.*;
/**
* Created by feirate on 2016/7/25.
* 练习 2.1:
* 编写一个程序,该程序可以在标准输出里以字母的形式输出你姓名的大写字母,
* 输出结果高度有 9 行。每个大写字母都应该由一堆 * 组成。例如,如果你姓名的大写字母是“DJE”,那么输出应该是这样的:
*/
public class yourName {
public static final List<String> D = new ArrayList<>();
static {
D.add("****** ");
D.add("** ** ");
D.add("** ** ");
D.add("** ** ");
D.add("** ** ");
D.add("** ** ");
D.add("** ** ");
D.add("** ** ");
D.add("***** ");
}
public static final Map<String,List> dicMapper = new HashMap<>();
static {
dicMapper.put("D",D);
}
public static void main(String args[]){
String input = "DDD";
char[] chars = input.toCharArray();
System.out.println(chars);
List<String> charList = printChar(chars);
Iterator iterator = charList.iterator();
while (iterator.hasNext()){
System.out.println((String)iterator.next());
}
}
private static List<String> printChar(char[] chars) {
List<String> lines = new ArrayList<>();
for (int i =0;i<chars.length;i++){
String str = String.valueOf(chars[i]);
if(dicMapper.containsKey(str)){
Iterator iterator = dicMapper.get(str).iterator();
int index =0;
while (iterator.hasNext()){
String theChar = (String)iterator.next();
if(lines.size()<9){
lines.add(theChar);
} else {
String plus = lines.get(index);
lines.set(index, plus + theChar);
}
index++;
}
}
}
return lines;
}
}