当前位置:首页 » 编程语言 » 心形java

心形java

发布时间: 2022-11-02 08:55:30

1. java中怎样打印心形

package com.zeph.j2se.alg;

public class Heart {
int HighLevel(int wide) {
int i = 0, j = 0, k = 0, t = 0, m = 0, n = 0, count = 1;// i控制循环内高度,j控制每行前面空格,k控制输出的*数
// t控制高层星号中间空格,m记录高层最底行的星数,以下逐行增4
// n记录顶行空个数,以下逐行减4;count记录高层高度,与high无关
m = (wide - 4) / 2;
do {
count++;
m -= 4;
} while (m > 4);
if ((wide - 4) % 2 == 0)// 区别对待奇偶宽度,奇数中间最小空1个,偶数最小空两个
{
n = 2 + 4 * (count - 1);
m--;
} else
n = 1 + 4 * (count - 1);

for (i = 0; i < count; i++) {
for (j = (count - i) * 2; j > 0; j--)
System.out.print(" ");
for (k = 0; k < m; k++)
System.out.print("*");
for (t = 0; t < n; t++)
System.out.print(" ");
for (k = 0; k < m; k++)
System.out.print("*");
m += 4;
n -= 4;
System.out.print("\n");
}

return 0;
}

int LowLevel(int wide) {
int i = 0, j = 0, k = 0;// i控制输出行,j控制输出每行前的空格,k控制输出*
int high = 0, tmp = wide;
do// 计算所需高度
{
high++;
tmp -= 4;
} while (tmp > 4);
high += 1;

for (i = 0; i < high; i++) {
for (j = 0; j < 2 * i; j++)
System.out.print(" ");
for (k = wide - 4 * i; k > 0; k--)
System.out.print("*");
System.out.print("\n");
}
return 0;
}

public static void main(String[] args) {
int wide = 30;
Heart heart = new Heart();
heart.HighLevel(wide);
heart.LowLevel(wide);
}
}

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

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

心形线方程如图

3. for语句 输出心形(java)

for语句输出心形(java)的方法如下:

  1. 使用eclipse,创建一个Java文件命名为Test.java

(3)心形java扩展阅读:

for 语句表达式:

表达式1:一般为赋值表达式,给控制变量赋初值;

表达式2:关系表达式或逻辑表达式,循环控制条件;

表达式3:一般为赋值表达式,给控制变量增量或减量。

4. ❤️的代码怎么写

摘要 您好,以下是总结望采纳

5. Java打印心形图形的算法

import java.util.Scanner;

public class Test {

static void draw(int n) {
int i, j;
for (i = 1 - (n >> 1); i <= n; i++)
if (i > 0) {
for (j = 0; j < i; 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; j < n; j++)
System.out.print(" ");
System.out.print(" *");
for (j = 1; j < n; j++)
System.out.print(" ");
System.out.print(" *\n");
} else {
for (j = i; j < 0; j++)
System.out.print(" ");
for (j = 1; j <= n + 2 * i + 1; j++)
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 = 1; j <= -1 - 2 * i; j++)
System.out.print(" ");
for (j = 1; j <= n + 2 * i + 1; j++)
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);

}
}

6. Java 心形图形

public class Heart {
public static void main(String[] args) {
int size = 4;
int number = 7;

for (int i = 0; i <= size; i++) {
for (int j = 4; j <= 4 - i; j--)//变量j一直自减1 最后是负数的时候也满足条件 所以无限循环了
System.out.print(" ");
for (int j = 1; j <= i; j++)//
System.out.print("*");
for (int j = size; j <= size - i; j--)//变量j一直自减1 最后是负数的时候也满足条件 所以无限循环了

System.out.print(" ");
for (int j = 1; j <= i; j++)
System.out.print("*");

System.out.println();

}

for (int k = number; k <= number; k--) {
System.out.print("*");

System.out.println();
}

}
}

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

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

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

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

9. 如何用java在页面上用循环打印一个爱心形状

import java.util.Scanner;

public class test{

static void draw(int n)
{
int i,j;
for (i=1-(n>>1);i<=n;i++)
if (i>0)
{
for (j=0;j<i;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;j<n;j++) System.out.print(" ");
System.out.print(" *");
for (j=1;j<n;j++) System.out.print(" ");
System.out.print(" *\n");
}
else
{
for (j=i;j<0;j++) System.out.print(" ");
for (j=1;j<=n+2*i+1;j++)
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=1;j<=-1-2*i;j++) System.out.print(" ");
for (j=1;j<=n+2*i+1;j++)
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 结果有点像爱心 还凑合着 你看看怎么样吧 哈

10. 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 (size<endSize){

eval(zoomText)

eval(zoomSize)

eval(closeIt)

size+=5;

setTimeout("zoom("+num+",'"+fn+"')",Zspeed)

}else{

eval(fn);

}

}

function fadeIt(num){

if (num<numColors){

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(num<numText){

zoom(num,'go('+gonum+')')

}else{

fadeIt(0)

}

}

</script>
<div id="zoom" align="center" style="position:absolute; top:150">

热点内容
易语言制作软件源码 发布:2025-01-09 15:03:27 浏览:260
scratch少儿编程是 发布:2025-01-09 15:01:34 浏览:712
javamd564加密 发布:2025-01-09 14:58:57 浏览:144
javaifint 发布:2025-01-09 14:57:32 浏览:487
怎么配好电脑配置 发布:2025-01-09 14:46:31 浏览:835
薯仔音频上传 发布:2025-01-09 14:45:49 浏览:991
猫追蝴蝶编程 发布:2025-01-09 14:30:05 浏览:355
花生视频脚本 发布:2025-01-09 13:43:38 浏览:839
锁相环c语言 发布:2025-01-09 13:43:37 浏览:969
e语言盗号源码 发布:2025-01-09 13:35:25 浏览:830