for循环题目:求代码打印出下图。 求用for循环语句打印出如下图所示: 1 1 2 1 1 2 3 2 1 1 2 3 4 3 2 1 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 public class Test { public static void main(String[] args) { for(int i=1; i<=4; i++) { int j; for(j=1; j<=i; j++) { System.out.print(j + " "); } for(j=j-2; j>=1; j--) { System.out.print(j + " "); } System.out.println(); } }} SORRY! 是我的图有问题,正确的图应该是第一行是个1,第二行是1加上空格加上2加上空格加上1,以此内推,到第4行! public class shishi { public static void main(String[] args) { getNum(1); } public static void getNum(int i){ for(int j=1;j<=i;j++){ for(int k=1;k<=(i-j)*2;k++){ System.out.print(" "); } for(int h=1;h<=j;h++){ System.out.print(h); System.out.print(" "); } for(int h=j-1;h>=1;h--){ System.out.print(h); System.out.print(" "); } for(int k=1;k<=(i-j)*2;k++){ System.out.print(" "); } System.out.println(); } } }//我也是新手,总觉得我写的复杂了点,你看看能不能优化 public class Test { public static void main(String[] args) { for(int i=1; i<=4; i++) { int j; for(j=4;j>i;j--){ System.out.print(" "); } for(j=1; j<=i; j++) { System.out.print(j + " "); } for(j=j-2; j>=1; j--) { System.out.print(j + " "); } System.out.println(); } }} 如何动态加载有继承关系的jar? 一些JAVA方面的疑问 连接sql2005老显示找不到合适驱动,求助!! java.nio 接受请求时ClassCastException 异常 关于流的问题 如何设置JButton的大小啊? 请问在JAVA中怎么调用UNIX指令(急) help,help me! 初学JAVA问一个很简单的问题 高手解答,需要这个程序输出结果的详细分析。谢谢! InputStream求助 连接ACCESS数据库检索
public class Test { public static void main(String[] args) {
for(int i=1; i<=4; i++) {
int j;
for(j=1; j<=i; j++) {
System.out.print(j + " ");
}
for(j=j-2; j>=1; j--) {
System.out.print(j + " ");
}
System.out.println();
}
}
}
public static void main(String[] args) {
getNum(1);
}
public static void getNum(int i){
for(int j=1;j<=i;j++){
for(int k=1;k<=(i-j)*2;k++){
System.out.print(" ");
}
for(int h=1;h<=j;h++){
System.out.print(h);
System.out.print(" ");
}
for(int h=j-1;h>=1;h--){
System.out.print(h);
System.out.print(" ");
}
for(int k=1;k<=(i-j)*2;k++){
System.out.print(" ");
}
System.out.println();
}
}
}
//我也是新手,总觉得我写的复杂了点,你看看能不能优化
for(int i=1; i<=4; i++) {
int j;
for(j=4;j>i;j--){
System.out.print(" ");
}
for(j=1; j<=i; j++) {
System.out.print(j + " ");
}
for(j=j-2; j>=1; j--) {
System.out.print(j + " ");
}
System.out.println();
} }}