我想写一个方法,用大写字母显示一个人的首字母,用相应的小写字母制作大写字母,例如:
MMMMMMMMMM CCCCCCCCC
MM MM MM CCCCCCCCC
MM MM MM CC
MM MM MM CC
MM MM MM CC
MM MM CCCCCCCCC
MM MM CCCCCCCCC
关于我应该如何去做的任何想法?
我想写一个方法,用大写字母显示一个人的首字母,用相应的小写字母制作大写字母,例如:
MMMMMMMMMM CCCCCCCCC
MM MM MM CCCCCCCCC
MM MM MM CC
MM MM MM CC
MM MM MM CC
MM MM CCCCCCCCC
MM MM CCCCCCCCC
关于我应该如何去做的任何想法?
第一步是有一种方法来创建每个单独的字母(A、B、...、Z)。将这些存储为String[]
s。例如,您的 M 将是:
{MMMMMMMMMM, MM MM MM, MM MM MM, MM MM MM, MM MM MM, MM MM, MM MM}
我刚刚获取了所有的行并将它们存储为一个数组。现在如果你有 2 String[]
,比如说letter1
and letter2
,你可以像这样“连接”它们:
String[] concat = new String[letter1.length];
for (int i = 0 ; i < concat.length ; i++)
concat[i] = letter1[i] + "\t" + letter2[i];
现在您只需打印:
for (String s : concat)
System.out.println(s);
// letter1 and letter2 would be created by some other method that you must define
String[] letter1 = new String[]{"MMMMMMMMMM", "MM MM MM", "MM MM MM", "MM MM MM", "MM MM MM", "MM MM", "MM MM"};
String[] letter2 = new String[]{"CCCCCCCCC" , "CCCCCCCCC", "CC ", "CC ", "CC ", "CCCCCCCCC", "CCCCCCCCC"};
String[] concat = new String[letter1.length];
for (int i = 0 ; i < concat.length ; i++)
concat[i] = letter1[i] + "\t" + letter2[i];
for (String s : concat)
System.out.println(s);