【发布时间】:2012-05-19 22:50:17
【问题描述】:
这里是打印一个下一个三角形的java代码, 将它们命名为 A、B、C、D;我的问题是如何将它们打印在*同一级别*
public class ex_5_10 {
public static void main(String args[]){
// (A)
System.out.println("(A)") ;
for(int row = 0 ; row < 10 ; row++){
for(int column = 0 ; column < 10 ; column++){
if(column > row) continue ;
System.out.print("*");
}
System.out.println() ;
}
//*********************************
// (B)
System.out.println("(B)") ;
for(int row = 0 ; row < 10 ; row++){
for(int column = 0 ; column < 10 ; column++){
if(column < row) continue ;
System.out.print("*");
}
System.out.println() ;
}
//********************************
//(C)
System.out.println("(C)") ;
for(int row = 0 ; row < 10 ; row++){
for(int column = 0 ; column < 10 ; column++){
if( column < row ) System.out.print(" ") ;
else System.out.print("*");
}
System.out.println() ;
}
// (D)
System.out.println("(D)") ;
for(int row = 0 ; row < 10 ; row++){
for(int column = 10 ; column >= 0 ; column--){
if( column > row ){ System.out.print(" ") ; }
else {System.out.print("*"); }
}
System.out.println() ;
}
}
}
所以上面的java代码会打印这个:
*
**
***
***
**
*
***
**
*
*
**
***
现在我需要在同一级别上打印相同的数字!
* *** *** *
** ** ** **
*** * * ***
请帮助我! 我正在寻找你的答案! 提前致谢
【问题讨论】:
-
看看这个:[gotoXY Discussion][1]这将有助于[1]:stackoverflow.com/questions/1001335/…
-
你是否允许使用额外的图书馆或者你必须修改这个作业?
-
伙计,这个练习告诉我们只使用嵌套的 for 循环!