给出一个固定数字,生成如下图的数据

beney734097916 2013-11-14 09:22:15



左=上*2+1; 右=上*2+2;
...全文
138 1 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
chro008 2013-11-14
  • 打赏
  • 举报
回复
package xiaoming.test;

import java.util.Scanner;;

public class Test {

	/**
	 * @param args
	 */

	public static void main(String[] args) {
		Scanner input=new Scanner(System.in);
		System.out.println("please input the sorce num:");
		int sn=input.nextInt();
		System.out.println("please input the counts lines");
		int lines=input.nextInt();
		int x=lines;
		int y=(int)Math.pow(2, x);
		int a[][]=new int[x][y];
		a[0][0]=sn;
		for(int i=1;i<x;i++){
			for(int j=0;j<Math.pow(2, i);j++){
				if(j%2==0)
					a[i][j]=a[i-1][j/2]*2+1;
				else if(j%2==1)
					a[i][j]=a[i-1][j/2]*2+2;
			}
		}
		System.out.println("\n");
		for(int i=0;i<x;i++){
			for(int j=0;j<Math.pow(2,i);j++){
				System.out.print(a[i][j]+" ");
			}
			System.out.println("\n");
		}
	}

}

33,027

社区成员

发帖
与我相关
我的任务
社区描述
数据结构与算法相关内容讨论专区
社区管理员
  • 数据结构与算法社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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