我想写一个方法,用大写字母显示一个首字母,用相应的小写字母制作大字母,例如:
MMMMMMMMMM CCCCCCCCC
MM MM MM CCCCCCCCC
MM MM MM CC
MM MM MM CC
MM MM MM CC
MM MM CCCCCCCCC
MM MM CCCCCCCCC
关于我应该怎么做的任何想法?
答案 0 :(得分:2)
第一步是创建一个单独的字母(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
和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);