大橙子网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
用方程的话肯定输出不会和你的图完全一致
网站建设哪家好,找创新互联!专注于网页设计、网站建设、微信开发、重庆小程序开发、集团企业网站建设等服务项目。为回馈新老客户创新互联还提供了郸城免费建站欢迎大家使用!
心形线方程如图
用上面行第二个比较简单,程序如下
#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)坐标不会是边缘,打印空格,否则是边缘,打印星号
最终结果如图
分析:
1.首先爱心分成两半前面三行左右一样右边就可以通过左边反相得到
中间两行是个长方形,剩下的就是个倒等腰三角形
2.在或者,长得不太像- -
System.out.println(" ** **");
for (int i = 4; i 10; i++) {
for (int a = 0; a i; a++) {
System.out.print(" ");
}
for (int b = 1; b = 2 * 9 - 2 * i - 1; b++) {
System.out.print("*");
}
System.out.print("\n");
}
** **
*********
*******
*****
***
*
把如下代码加入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"
凑合着看吧,刚实现了一个,代码如下:
public class Test {
public static void main(String args[]) {
System.out.println("this is XX!");
System.err.println(" ** ** ");
System.err.println(" ** ** ** ** ");
System.err.println(" ** ** ** ");
System.err.println(" ** ** ");
System.err.println(" ** ** ");
System.err.println(" ** ** ");
System.err.println(" ** ");
}
}
复制到百度里面有点乱,你要是会用MyEclipse的话直接Ctrl+Shift+F;
如果喜欢的话希望采纳@~
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);
}
}