「java中心形」java圆心坐标
今天给各位分享java中心形的知识,其中也会对java圆心坐标进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!
本文目录一览:
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);
}
}
如何用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();
}
}
for语句 输出心形(java)
for语句输出心形(java)的方法如下:
使用eclipse,创建一个Java文件命名为Test.java
2.系统自动建立Test类及主函数。
3.输入以下代码:
public class Test{
public static void main (String []args){
int k=5; //控制心型大小
for ( int i=0;i=k*2;i++){
for (int j=0;j=k*4;j++){
if (((i-k)*(i-k)+(j-k)*(j-k)==k*ki=k )||( (j-3*k)*(j-k*3)+(i-k)*(i-k)==k*ki=k)
||(((2*k-i)-2*k)*((2*k-i)-2*k)+(j-2*k)*(j-2*k)==k*k*4 ) )
{ if (i==0j==0||i==0j==k*4) System.out.print(" ");
else { System.out.print("*");}
}
else System.out.print(" ");
}
System.out.println();
}
}
}
4.保存并运行程序
扩展资料:
for 语句表达式:
表达式1:一般为赋值表达式,给控制变量赋初值;
表达式2:关系表达式或逻辑表达式,循环控制条件;
表达式3:一般为赋值表达式,给控制变量增量或减量。
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语言编写一个心形代码?
1,首先用图纸画一个心形。
2,使用方框,把每笔,做成一个点。
3,输出这些点。就可以了。
希望能帮到你
java中心形的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于java圆心坐标、java中心形的信息别忘了在本站进行查找喔。
发布于:2022-11-22,除非注明,否则均为
原创文章,转载请注明出处。