java心形代码?

hackwuhen 2012-07-10 11:35:18
求java心型代码
...全文
599 点赞 收藏 3
写回复
3 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
fb729222507 2012-09-04
public class hehe {
public static void main(String[] args) {
draw3R(5);
}

private static void draw3R(int n) {
boolean[][] arr = new boolean[3 * n - 1][4 * n - 1];
draw3(arr, 0, 0, n, true);
draw3(arr, 0, 2 * n - 1 + 1, n, true);
draw3(arr, n, 0, 2 * n - 1, false);
print(arr);
}

private static void print(boolean[][] arr) {
for (int i = 0; i < arr.length; i += 1) {
for (int j = 0; j < arr[i].length; j += 1) {
System.out.print(arr[i][j] ? "*" : " ");
}
System.out.println();
}
}

private static void draw3(boolean[][] arr, int x, int y, int n, boolean order) {
for (int i = 0; i < n; i++) {
if (order) {
for (int j = y + (n - i - 1); j <= y + (2 * n - 1) - (n - i); j++) {
arr[i][j] = true;
}
} else {
for (int j = y + i + 1; j <= y + 2 * n - 1 - i; j++) {
arr[i+x][j] = true;
}
}
}
}
}
回复
fb729222507 2012-09-04
public class hehe {
public static void main(String[] args) {
draw3R(5);
}

private static void draw3R(int n) {
boolean[][] arr = new boolean[3 * n - 1][4 * n - 1];
draw3(arr, 0, 0, n, true);
draw3(arr, 0, 2 * n - 1 + 1, n, true);
draw3(arr, n, 0, 2 * n - 1, false);
print(arr);
}

private static void print(boolean[][] arr) {
for (int i = 0; i < arr.length; i += 1) {
for (int j = 0; j < arr[i].length; j += 1) {
System.out.print(arr[i][j] ? "*" : " ");
}
System.out.println();
}
}

private static void draw3(boolean[][] arr, int x, int y, int n, boolean order) {
for (int i = 0; i < n; i++) {
if (order) {
for (int j = y + (n - i - 1); j <= y + (2 * n - 1) - (n - i); j++) {
arr[i][j] = true;
}
} else {
for (int j = y + i + 1; j <= y + 2 * n - 1 - i; j++) {
arr[i+x][j] = true;
}
}
}
}
}
回复
相关推荐
发帖
Java
创建于2007-09-28

4.7w+

社区成员

Java相关技术讨论
申请成为版主
帖子事件
创建了帖子
2012-07-10 11:35
社区公告
暂无公告