首页 > 编程语言 > 详细

面试题(平面图形题 用二维数组解决)

时间:2015-03-23 11:13:01      阅读:248      评论:0      收藏:0      [点我收藏+]

package cn.itcast.demo;

import org.junit.Test;

//面试题
public class demo1 {
/*
*
*            3       7
*          2  4   6   8
*        1      5        9
*

*     arr[2][0]

*     arr[1][1]

*     arr[0][2]

*     arr[1][3]

*     arr[2][4]

*     arr[1][5]

*     arr[0][6]

*     arr[1][7]

*     arr[2][8]


* 平面图形题 用二维数组解决
*/
@Test
public void test() {
int num = 9;
int arr[][] = new int[3][9];
int x = 2;
int y = 0;
boolean order = false;
for (int i = 1; i <= 9; i++) {
arr[x][y] = i;
y++;

if (order)
x++;
else
x--;
if (x < 0) {
order = true;
x = x + 2;
}
if (x > 2) {
order = false;
x = x - 2;
}
}

for (int i = 0; i < arr.length; i++) {
for (int j = 0; j < arr[i].length; j++) {
if (arr[i][j] == 0)
System.out.print(" ");
else
System.out.print(arr[i][j]);
}
System.out.println();
}
}

}

面试题(平面图形题 用二维数组解决)

原文:http://www.cnblogs.com/xiaohuihui123/p/4359076.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!