在java中用“\t”和“\n”和*编写一个心形的轮廓怎么写 求大神
发布网友
发布时间:2022-04-28 16:48
我来回答
共1个回答
热心网友
时间:2023-09-12 15:57
空心
public class Test{
static float count(float x, float y) {
return (float) (Math.pow((x * x + y * y - 1), 3) - x * x * y * y * y);
}
public static void printEmpty() {
int height = 50, width = 100;
int heart[][] = new int[height][width];
float hx = 0.0f, hy = 0.0f;
for (int y = height / 2; y > -height / 2; y--) {
for (int x = -width / 2; x < width / 2; x++) {
hx = (float) x / (float) (width / 2.8f);
hy = (float) (y) / (float) (height / 2.8f);
if (count(hx, hy) <= 0.0f) {
heart[height / 2 - y][x + width / 2] = 1;
}
}
}
for (int y = 1; y < height - 1; y++) {
for (int x = 1; x < width - 1; x++) {
if (heart[y][x] == 1
&& !(heart[y][x - 2] == 1 && heart[y][x + 2] == 1
&& heart[y - 1][x] == 1 && heart[y + 1][x] == 1)) {
System.out.print("*");
} else {
System.out.print(" ");
}
}
System.out.println();
}
System.out.println();
}
public static void main(String[] args) {
printEmpty();
}
}