打印M的方法 java

来源:互联网 发布:古巴网络 编辑:程序博客网 时间:2024/05/18 01:00
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("");
}
}
}
0 0
原创粉丝点击