package com.test;
public class printM {
public static void main(String[] args) {
test(4, 13);
}
public static void test(int xLength, int yLength) {
int arr[][] = new int[xLength][yLength];
boolean flag = true;
int j = xLength - 1;
int tool = -1;
for (int i = 0; i < yLength; i++) {
if (j == xLength - 1 && !flag) {
tool = -1;
flag = true;
}
if (j == 0 && flag) {
tool = 1;
flag = false;
}
arr[j][i] = i + 1;
j += tool;
}
for (int x = 0; x <= xLength - 1; x++) {
for (int y = 0; y < yLength; y++) {
if (arr[x][y] == 0) {
System.out.print(" ");
} else {
System.out.print(arr[x][y]);
}
}
System.out.println("");
}
}
}
打印M的方法 java
于 2014-12-23 17:05:10 首次发布