public class foo{ public static void main(String[] arg){ new foo().print(5); } public void print(int c){ for (int i = 1; i <= c; i++) { for (int j = 1; j <= 2*c-1; j++) { if(j<=c) System.out.print((j+i<=c)?" ":Integer.toString(j+i-c)); else System.out.print((j-i>=c)?" ":Integer.toString(c-j+i)); } System.out.println(""); } } }
能运行的一个 import java.lang.*; public class Test { public static void main(String args[]){ int Max = 5; for(int i = 1 ;i <=Max ;i++){ int space = Max-i; while((space--)>0) System.out.print(" "); space = 1; while(space<=i) System.out.print(space++); space = i-1; while(space>=1) System.out.print(space--); System.out.print("\n"); } } }
public class foo{ public static void main(String[] arg){ new foo().print(1,5); } public void print(int i,int c){ for (int j = 1; j <= 2*c-1; j++) { if(j<=c-i||j>=c+i) System.out.print(" "); else System.out.print(i-Math.abs(j-c)); } if(++i<=c){ System.out.println(""); print(i,c); } } }
public class Print { public static void main(String[] args) { int number = 6; for( int i = 0; i < number ; i ++ ) { for( int n = 0; n < number - 1 - i; n ++ ) System.out.print(" "); for( int n = 1; n <= i + 1 ; n++) System.out.print(n); for( int n = i ; n >= 1 ; n--) System.out.print(n); for( int n = 0; n < number - 1 - i; n ++ ) System.out.print(" "); System.out.print("\n"); } } }
public static void main(String[] arg){
new foo().print(5);
}
public void print(int c){
for (int i = 1; i <= c; i++) {
for (int j = 1; j <= 2*c-1; j++) {
if(j<=c)
System.out.print((j+i<=c)?" ":Integer.toString(j+i-c));
else
System.out.print((j-i>=c)?" ":Integer.toString(c-j+i));
}
System.out.println("");
}
}
}
import java.lang.*;
public class Test
{
public static void main(String args[]){
int Max = 5;
for(int i = 1 ;i <=Max ;i++){
int space = Max-i;
while((space--)>0) System.out.print(" ");
space = 1;
while(space<=i) System.out.print(space++);
space = i-1;
while(space>=1) System.out.print(space--);
System.out.print("\n");
}
}
}
public static void main(String[] arg){
new foo().print(1,5);
}
public void print(int i,int c){
for (int j = 1; j <= 2*c-1; j++) {
if(j<=c-i||j>=c+i) System.out.print(" ");
else System.out.print(i-Math.abs(j-c));
}
if(++i<=c){
System.out.println("");
print(i,c);
}
}
}
{ public static void main(String[] args)
{
int number = 6;
for( int i = 0; i < number ; i ++ )
{
for( int n = 0; n < number - 1 - i; n ++ )
System.out.print(" ");
for( int n = 1; n <= i + 1 ; n++)
System.out.print(n);
for( int n = i ; n >= 1 ; n--)
System.out.print(n);
for( int n = 0; n < number - 1 - i; n ++ )
System.out.print(" ");
System.out.print("\n");
}
}
}