Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Java SE 综合讨论区 » 编程/算法/API  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 Re:public int[][] init(int n){}能不能返回数组的句柄? [Re:234aini]
234aini





发贴: 43
积分: 0
于 2004-11-13 14:13 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list

class Array
{
public static void main(String[] args)
{
int argc=args.length;
if(argc!=1){System.out.println("Sytnax Error");return;}
int n=new Integer(args[0]).intValue();
if(n>9){
System.out.println("This may run,but this will made the array FEATURE no rule !");
}

int[][] a = t(n);

for(int j = 0; j <n; j++ )
for(int i=0;i<2*n-1;i++)
{

System.out.print(" "+a[j][i]);
if(i==(2*n-2))
System.out.println("\n");
}
}

public static int[][] t(int n)//初始化一个n行2n-1列的数组
{
int m=n;
int[][] a=new int[n][2*n-1];
for(int i=0;i<n;i++)
a[n-1][i]=i+1;

for(int i=n;i<2*n-1;i++)
a[n-1][i]=--m;

for(int j=0;j<n-1;j++)
for(int i=0;i<2*n-1;i++)
{
a[j][i]=a[n-1][i]-(n-j-1);
if(a[j][i]<0) a[j][i]=0;
}
return a;
}

}

已经可以打印了,效果还不错。。。。。
不多又多了一个问题,怎么样让那些零都不打印,但是可以同样达到那样金字塔的效果呢?想应该有好多种方法的。。。


why edited on 2004-11-13 18:52


话题树型展开
人气 标题 作者 字数 发贴时间
38437 public int[][] init(int n){}能不能返回数组的句柄? 234aini 30 2004-11-13 01:27
29649 Re:public int[][] init(int n){}能不能返回数组的句柄? Lawme 306 2004-11-13 07:37
29671 Re:public int[][] init(int n){}能不能返回数组的句柄? 234aini 89 2004-11-13 12:56
30028 Re:public int[][] init(int n){}能不能返回数组的句柄? 234aini 1115 2004-11-13 14:13

flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923