资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

心形java代码 心形c语言程序代码

如何用JAVA语言编写一个心形代码?用循环语句

1,首先用图纸画一个心形。 2,使用方框,把每笔,做成一个点。 3,输出这些点。就可以了。 希望能帮到你

成都创新互联2013年开创至今,先为长春等服务建站,长春等地企业,进行企业商务咨询服务。为长春企业网站制作PC+手机+微官网三网同步一站式服务解决您的所有建站问题。

如何用JAVA语言编写一个心形代码?

1,首先用图纸画一个心形。

2,使用方框,把每笔,做成一个点。

3,输出这些点。就可以了。

希望能帮到你

如何用java中的for输出心形

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();

}

}

用java或者c程序输出如下图的这种简单心形,谁能给我讲讲思路。加上程序示例更好

用方程的话肯定输出不会和你的图完全一致

心形线方程如图

用上面行第二个比较简单,程序如下

#include stdio.h

bool draw(float x, float y)

{

float a = x * x + y * 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(x + 0.05, y);

bool up = draw(x, y + 0.1);

bool down = draw(x, y - 0.1);

if (left  right  up  down)

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心形代码

把如下代码加入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在页面上用循环打印一个爱心形状

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代码 心形c语言程序代码
标题路径:http://cdkjz.cn/article/dooiecp.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

业务热线:400-028-6601 / 大客户专线   成都:13518219792   座机:028-86922220