各位大哥!进来看一下,帮个忙!!

twismning 2004-11-06 12:30:31
如何用for循环输出下面结果:
1
1 3 1
1 3 5 3 1
1 3 5 7 5 3 1
1 3 5 7 9 7 5 3 1
...全文
67 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
congliu 2004-11-06
  • 打赏
  • 举报
回复
up
mq612 2004-11-06
  • 打赏
  • 举报
回复
public class Test {
/**
* 构造
* @param c 层数
*/
public Test(int c) {
for(int i=0;i<c;i++){
//实现空格
for(int i_=0;i_<c-i-1;i_++){
System.out.print(" ");
}
//打印数字
for(int i__=0;i__<i * 2 + 1;i__++){
if(i__<=i){
//行数字升序
System.out.print(i__ * 2 + 1);
}else{
//行数字降序
System.out.print((i * 2 + 1) - ((i__ - i) * 2));
}
}
//换行
System.out.println("");
}
}

public static void main(String[] args) {
new Test(5);
//new Test(Integer.parseInt(args[0])); //需要运行时加具体行的参数
}
}
pier2008 2004-11-06
  • 打赏
  • 举报
回复
import java.io.*;
class OutTest
{
public static void main(String args[])
{
int m=Integer.parseInt(args[0]);
for(int i=1;i<m;i++)
{
for(int j=0;j<m-1;j++)
System.out.println();
for(j=0;j<2*i-1;j++)
System.out.print(i);
System.out.println();
}
}
}

23,407

社区成员

发帖
与我相关
我的任务
社区描述
Java 非技术区
社区管理员
  • 非技术区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧