控制台要求输出:
(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) {
String str = "abcdefghi";
String strTemp = "";
for(int line=1;line <=str.length();line++){
int start = 0;
for(int i=1;i<=((str.length()%line==0)? str.length()/line : str.length()/line+1);i++){
if((start+line)<=str.length() ){
strTemp = str.substring(start,(start+line));
}else{
strTemp = str.substring(start,str.length());
}
if(i!=((str.length()%line==0)? str.length()/line : str.length()/line+1)){
System.out.print("(" + strTemp + ")," );
}else{
System.out.print("(" + strTemp + ")" );
}
start += line;
}
System.out.println();
}
}
}