以下是Java实现爱心表白的代码:
public class <em>Love</em> { public static void main(String[] args) { double x, y, size; char[][] s = new char[30][80]; for (int i = 0; i < 30; i++) { for (int j = 0; j < 80; j++) { s[i][j] = ' '; } } for (double i = 0; i < 2 * Math.PI; i += 0.05) { for (double j = 0; j < 2 * Math.PI; j += 0.1) { x = 2 * Math.sin(i) * (Math.pow(Math.sin(j), 2)) + 0.5; y = Math.cos(j) * Math.sin(i) + 0.5; size = (x * x + y * y) * 0.1; s[(int) (y * 30)][(int) (x * 40 + 20)] = size > 1 ? ' ' : "<em>LOVE</em>".charAt((int) (size * 4)); } } for (int i = 0; i < 30; i++) { for (int j = 0; j < 80; j++) { System.out.print(s[i][j]); } System.out.println(); } } }
版权声明:
本文来源网络,所有图片文章版权属于原作者,如有侵权,联系删除。
本文网址:https://www.bianchenghao6.com/h6javajc/13060.html