用java打出心形的代码 java打爱心

java心形代码把如下代码加入body区域中
style type="text/css"
body
{
background-color:#FFFFFF;
font-family: Arial;
font-size:10pt;
}
/style
script
text=new Array('www','njcatv','net','需要放大的
/\/\
\/
\/
文字')
var numText=4
color=new Array('#000000','#2F2F2F','#4F4F4F','#7F7F7F','#408080')
var numColors=5
var endSize=70
var Zspeed=30
var Cspeed=200
var font='Arial Black'
var hide=false
var size=10
var gonum=0
var ie, n;
if (document.all) {
n=0
ie=1
zoomText='document.all.zoom.innerText=text[num]'
zoomSize='document.all.zoom.style.fontSize=size'
closeIt=""
fadeColor="document.all.zoom.style.color=color[num]"
}
if (document.layers) {
n=1;ie=0
zoomText=""
zoomSize="document.zoom.document.write('p align=\"center\" style=\"font-family:' font '; font-size:' size 'px; color:' color[0] '\"' text[num] '/p')"
closeIt="document.zoom.document.close()"
fadeColor="document.zoom.document.write('p align=\"center\" style=\"font-family:' font '; font-size:' endSize 'px; color:' color[num] '\"' text[numText-1] '/p')"
}
function zoom(num,fn){
if (sizeendSize){
eval(zoomText)
eval(zoomSize)
eval(closeIt)
size =5;
setTimeout("zoom(" num ",'" fn "')",Zspeed)
}else{
eval(fn);
}
}
function fadeIt(num){
if (numnumColors){
eval(fadeColor)
eval(closeIt)
num =1;
setTimeout("fadeIt(" num ")",Cspeed)
}else{
hideIt()
}
}
function hideIt(){
if(hide){
if(ie)document.all.zoom.style.visibility="hidden"
if(n)document.layers.zoom.visibility="hidden"
}
}
function init(){
if(ie){
document.all.zoom.style.color=color[0]
document.all.zoom.style.fontFamily=font
}
if(ie || n) go(0)
}
function go(num){
gonum =1
size=10
if(numnumText){
zoom(num,'go(' gonum ')')
}else{
fadeIt(0)
}
}
/script
div id="zoom" align="center" style="position:absolute; top:150"
用java或者c程序输出如下图的这种简单心形,谁能给我讲讲思路 。加上程序示例更好用方程的话肯定输出不会和你的图完全一致
心形线方程如图
用上面行第二个比较简单,程序如下
#include stdio.h
bool draw(float x, float y)
{
float a = x * xy * y - 1.0;
float b = x * x * y * y * y;
return a * a * a - b = 0;
}
int main(int argc, char* argv[])
{
for (float y = 1.5; y = -1.5; y -= 0.1)
{
for (float x = -1.2; x = 1.2; x= 0.05)
{
if (draw(x, y))
{
bool left = draw(x - 0.05, y);
bool right = draw(x0.05, y);
bool up = draw(x, y0.1);
bool down = draw(x, y - 0.1);
if (leftrightupdown)
printf(" ");
else
printf("*");
}
else
printf(" ");
}
printf("\n");
}
return 0;
}
draw函数是判断(x , y)坐标是否在心形范围内
主函数循环 , y取值±1.5之间,步长0.1,x取值±1.2之间,步长0.05
如果(x,y)坐标在心形范围外打印空格
如果(x,y)坐标在心形范围内,由于这个心是空心的,要继续判断是不是心形边缘,判断周围4个点坐标 , 如果都在范围内,表示(x , y)坐标不会是边缘 , 打印空格,否则是边缘 , 打印星号
最终结果如图
如何用java在页面上用循环打印一个爱心形状import java.util.Scanner;
public class test{
static void draw(int n)
{
int i,j;
for (i=1-(n1);i=n;i)
if (i0)
{
for (j=0;ji;j) System.out.print("");
for (j=1;j=2*(n-i) 1;j)
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=1;jn;j) System.out.print("");
System.out.print(" *");
for (j=1;jn;j) System.out.print("");
System.out.print(" *\n");
}
else
{
for (j=i;j0;j) System.out.print("");
for (j=1;j=n 2*i 1;j)
if (i==1-(n1)) System.out.print(" *");
else if (j==1||j==n 2*i 1) System.out.print(" *");
else System.out.print("");
for (j=1;j=-1-2*i;j) System.out.print("");
for (j=1;j=n 2*i 1;j)
if (i==1-(n1)) 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 结果有点像爱心 还凑合着 你看看怎么样吧 哈
如何用JAVA语言编写一个心形代码?1,首先用图纸画一个心形 。
2 , 使用方框,把每笔 , 做成一个点 。
3 , 输出这些点 。就可以了 。
希望能帮到你
【用java打出心形的代码 java打爱心】关于用java打出心形的代码和java打爱心的介绍到此就结束了 , 不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站 。

    推荐阅读