帮我写一个java爱心
时间: 2023-03-28 18:00:59 浏览: 100
好的,我可以帮你写一个 Java 爱心。以下是代码:
```
public class Heart {
public static void main(String[] args) {
double x, y, size;
for (y = 1.5; y > -1.5; y -= .1) {
for (x = -1.5; x < 1.5; x += .05) {
size = x * x + y * y - 1;
System.out.print(size * size * size - x * x * y * y * y <= . ? "*" : " ");
}
System.out.println();
}
}
}
```
这段代码可以输出一个简单的爱心图案。希望能对你有所帮助。
相关问题
帮我写一个java爱心代码
public class Heart {
public static void main(String[] args) {
int size = 10;
int[][] heart = new int[size][size];
for (int i = 0; i < size; i++) {
for (int j = 0; j < size; j++) {
heart[i][j] = 0;
}
}
for (int i = 0; i < size; i++) {
for (int j = 0; j < size; j++) {
if ((i <= size / 2 && j >= size / 2 - i && j <= size / 2 + i) ||
(i > size / 2 && j >= i - size / 2 && j <= size - (i - size / 2))) {
heart[i][j] = 1;
}
}
}
for (int i = 0; i < size; i++) {
for (int j = 0; j < size; j++) {
if (heart[i][j] == 1) {
System.out.print("*");
} else {
System.out.print(" ");
}
}
System.out.println();
}
}
}
帮我写一个java炫酷爱心代码
好的,以下是一个简单的Java炫酷爱心代码:
```
import java.awt.*;
import javax.swing.*;
public class Heart extends JFrame {
public Heart() {
setSize(500, 500);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);
setVisible(true);
}
public void paint(Graphics g) {
Graphics2D g2d = (Graphics2D) g;
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2d.setStroke(new BasicStroke(2));
g2d.setColor(Color.RED);
int x = 200;
int y = 200;
int width = 100;
int height = 100;
int controlX1 = x - width / 2;
int controlY1 = y - height / 2;
int controlX2 = x + width / 2;
int controlY2 = y - height / 2;
g2d.fillArc(controlX1, controlY1, width, height, , 180);
g2d.fillArc(controlX2, controlY2, width, height, , 180);
int[] xPoints = {x, x + width / 2, x - width / 2};
int[] yPoints = {y + height / 2, y - height / 2, y - height / 2};
g2d.fillPolygon(xPoints, yPoints, 3);
}
public static void main(String[] args) {
new Heart();
}
}
```
阅读全文