要求控制台输出:
(a),(b),(c),......(i)
(a,b),(c,d),(e,f),......
(ab,c),(d,e,f),(g,h,i),......
.
.
.
.
.
.
(a,b,c,d,e,f,g,h,i)
如上,就是从9个()到1个(),循环输出,题目有点难理解,感觉有点矛盾,哪位高手试试看。或者是理解不同
------解决方案--------------------
这个是输出
(a),(b),(c),(d),(e),(f),(g),(h),(i)
(ab),(cd),(ef),(gh),(i)
(abc),(def),(ghi)
(abcd),(efgh),(i)
(abcde),(fghi)
(abcdef),(ghi)
(abcdefg),(hi)
(abcdefgh),(i)
(abcdefghi)
------解决方案--------------------
public class Test1 {
public static void main(String[] args) {
output('a', 'i');
}
private static void output(char start, char end) {
int count = end - start + 1;
int add = 1;
for (int i = 0; i < count; ++i, ++add) {
for (int j = 0; j < count; j += add) {
System.out.print("(");
for (int k = j; k < Math.min(j + add, count); ++k) {
System.out.print((char) (start + k));
}
System.out.print(")");
if(j + add < count) {
System.out.print(",");
}
}
System.out.println();
}
}
}
------解决方案--------------------
各位大神写的那么复杂。也不给点注释、