# 面试了个JAVA的题,大家帮忙看看!

wj539h_1 2010-03-08 03:18:58

1

222
212
222

33333
32223
32123
32223
33333
...全文
485 26 打赏 收藏 转发到动态 举报

26 条回复

kyousuke 2010-03-09
• 打赏
• 举报

icy_csdn 2010-03-09
• 打赏
• 举报

http://blog.csdn.net/icy_csdn/archive/2010/03/09/5359153.aspx
cys0429831 2010-03-09
• 打赏
• 举报

Java codepublicclass test {publicstaticvoid main(String[] args) {long a=4;for (long i=0; i<2* a-1; i++) {for (long j=0; j<2* a-1; j++) {long m= Math.abs(i- a+1)+1;long n= Math.abs(j- a+1)+1;long x= m>?-

Dazzlingwinter 2010-03-09
• 打赏
• 举报

``````
for(int i=1; i<=N; i++) {
prints[N-i][N-i] = i;
for(int k=0; k<=2*(i-1);k++) {
prints[N-i][N-i+k] = i;
prints[N-i+k][N-i] = i;
prints[N-i+2*(i-1)][N-i+k] = i;
prints[N-i+k][N-i+2*(i-1)] = i;
}
}
``````

Dazzlingwinter 2010-03-09
• 打赏
• 举报

``````
public static final int N = 5;
public static void main(String[] args) {
System.out.println("Init-N=" + N);
int n = 2*N-1;
int[][] prints = new int[n][n];

for(int i=1; i<=N; i++) {
for(int j=0; j<2*i-1; j++) {
prints[N-i][N-i] = i;
for(int k=0; k<=2*(i-1);k++) {
prints[N-i][N-i+k] = i;
prints[N-i+k][N-i] = i;
prints[N-i+2*(i-1)][N-i+k] = i;
prints[N-i+k][N-i+2*(i-1)] = i;
}
}
}

for(int i=0; i<prints.length; i++) {
for(int j=0; j<prints[i].length; j++) {
System.out.print(prints[i][j] + "\t");
}
System.out.println();
}
}
}
//Result
//Init-N=5
//5	5	5	5	5	5	5	5	5
//5	4	4	4	4	4	4	4	5
//5	4	3	3	3	3	3	4	5
//5	4	3	2	2	2	3	4	5
//5	4	3	2	1	2	3	4	5
//5	4	3	2	2	2	3	4	5
//5	4	3	3	3	3	3	4	5
//5	4	4	4	4	4	4	4	5
//5	5	5	5	5	5	5	5	5
``````
b1412 2010-03-09
• 打赏
• 举报

Dazzlingwinter 2010-03-09
• 打赏
• 举报

zings 2010-03-08
• 打赏
• 举报

bayougeng 2010-03-08
• 打赏
• 举报

31113

• 打赏
• 举报

kyousuke 2010-03-08
• 打赏
• 举报

• 打赏
• 举报

value=MAX(|x-a|,|y-a|);

Java codepublicstaticvoid main(String[] args){int n=4;int center= n-1;int len= n*2-1;int v;int nx,ny;for(int y=0; y< len; y++){for(int x=0; x< len; x++){
nx= Math.abs(x- center)+1;
ny= Math.abs(y- center)+1;
v= nx> ny? nx : ny;
System.out.print(v);
}
System.out.println();
}

}

kyousuke 2010-03-08
• 打赏
• 举报

value=MAX(|x-a|,|y-a|);

``````
public static void main(String[] args){
int n = 4;
int center = n - 1;
int len = n * 2 - 1;
int v;
int nx,ny;
for(int y = 0; y < len; y++){
for(int x = 0; x < len; x++){
nx = Math.abs(x - center) + 1;
ny = Math.abs(y - center) + 1;
v = nx > ny ? nx : ny;
System.out.print(v);
}
System.out.println();
}

}
``````
jypapgl 2010-03-08
• 打赏
• 举报

3L必须得分

• 打赏
• 举报

Java codepublicclass test {publicstaticvoid main(String[] args) {long a=4;for (long i=0; i<2* a-1; i++) {for (long j=0; j<2* a-1; j++) {long m= Math.abs(i- a+1)+1;long n= Math.abs(j- a+1)+1;long x= m>?-

value=MAX(|x-a|,|y-a|);
kyousuke 2010-03-08
• 打赏
• 举报

Java codepublicclass test {publicstaticvoid main(String[] args) {long a=4;for (long i=0; i<2* a-1; i++) {for (long j=0; j<2* a-1; j++) {long m= Math.abs(i- a+1)+1;long n= Math.abs(j- a+1)+1;long x= m>?-

• 打赏
• 举报

``````public class Test {
public static void main(String[] args)throws Exception{

while(true){

try{
if(num>0){
printMatrix(num);
}else{
break;
}
}catch(Exception e){
break;
}
}

}

public static void printMatrix(int n){
if(n<1) return;

int size=2*n-1;
int val;

System.out.print("\n--------------------------------------\n");
for(int i=1;i<=size;i++){
for(int j=1;j<=size;j++){
val=Math.max(Math.abs(i-n)+1,Math.abs(j-n)+1);
System.out.print(String.format("%-4s", val));
}
System.out.print('\n');
}
System.out.print("--------------------------------------\n");
}
}
``````
SambaGao 2010-03-08
• 打赏
• 举报

Java codepublicclass test {publicstaticvoid main(String[] args) {long a=4;for (long i=0; i<2* a-1; i++) {for (long j=0; j<2* a-1; j++) {long m= Math.abs(i- a+1)+1;long n= Math.abs(j- a+1)+1;long x= m>?-

..
abc409992359 2010-03-08
• 打赏
• 举报

• 打赏
• 举报

62,621

• 近7日
• 近30日
• 至今