java如何画出爱心

Python018

java如何画出爱心,第1张

这个成不

1.首先获取爱心的数学表达式(函数);

2.然后Bitmap bit=new Bitmap(32,32)Graphics g=Graphics.FromImage(bit)

3.确定一个开始点startPoint,根据函数递归所有点,画出爱心。

分析:

首先爱心分成两半前面三行左右一样右边就可以通过左边反相得到

中间两行是个长方形,剩下的就是个倒等腰三角形

2.在或者,长得不太像- -

System.out.println("      ** **")

for (int i = 4i <10i++) {

for (int a = 0a <ia++) {

System.out.print(" ")

}

for (int b = 1b <= 2 * 9 - 2 * i - 1b++) {

System.out.print("*")

}

System.out.print("\n")

}

**  **

*********

*******

*****

***

*

import java.util.Scanner

public class test{

static void draw(int n)

{

int i,j

for (i=1-(n>>1)i<=ni++)

if (i>0)

{

for (j=0j<ij++) System.out.print(" ")

for (j=1j<=2*(n-i)+1j++)

if (j==1||j==2*(n-i)+1) System.out.print(" *")

else System.out.print(" ")

System.out.println("\n")

}

else

if (i==0)

{

System.out.print(" *")

for (j=1j<nj++) System.out.print(" ")

System.out.print(" *")

for (j=1j<nj++) System.out.print(" ")

System.out.print(" *\n")

}

else

{

for (j=ij<0j++) System.out.print(" ")

for (j=1j<=n+2*i+1j++)

if (i==1-(n>>1)) System.out.print(" *")

else if (j==1||j==n+2*i+1) System.out.print(" *")

else System.out.print(" ")

for (j=1j<=-1-2*ij++) System.out.print(" ")

for (j=1j<=n+2*i+1j++)

if (i==1-(n>>1)) System.out.print(" *")

else if (j==1||j==n+2*i+1) System.out.print(" *")

else System.out.print(" ")

System.out.print("\n")

}

}

public static void main(String[] args) {

System.out.println("Please input the size (n>=4):")

Scanner sc = new Scanner(System.in)

int n = sc.nextInt()

draw(n)

}

}先说明这个不是我写的 是看了有人用C语言写的 就顺便改成了java 结果有点像爱心 还凑合着 你看看怎么样吧 哈