class PrintOneRow {
private int length;
public PrintOneRow(int length) {
this.length = length;
}
public void printRow() {
for (int i = 0; i <= length/2; i++) {
System.out.print(i+1);
}
for (int j = 0; j < length/2; j++) {
System.out.print(length / 2 - j);
}
System.out.println();
}
}
class PrintNum {
public static void main(String[] args) {
int numOfRows = 9;
PrintOneRow printOneRow;
for (int i = 1; i <= numOfRows; i++) {
for (int j = 0; j < numOfRows - i; j++) {
System.out.print(" ");
}
new PrintOneRow(2 * i - 1).printRow();
}
}
}
public Test
{
public static void main(String[] args)
{
Scanner num=new Scanner(System.in);
int n=num.nextInt();
int i,j,k;
for(k=1;k
for(i=0;i
System.out.print(" ");
}
for(i=1,j=k;i<=j;i++)//输出前一段
{
System.out.print(i);
}
for(i=j-1,j=0;i>j;i--)//输出后半段
{
System.out.print(i);
}
System.out.println();
}
}
}
楼主,如果你想学java,这么简单的问题自己动动脑子比别人直接告诉你答案要强许多倍.如果你是学生,只是来应付学校的作业的话,拿旁边同学的copy一份就可以达到同样目的了.