如何打印: [英] How to print this:

查看:51
本文介绍了如何打印:的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何打印:



***

**

*



我尝试过:



how to print this:

***
**
*

What I have tried:

<!DOCTYPE html>
<html>
<head>
	<title>reverse</title>
</head>
<body>
<script>
	var n=prompt("enter your limit");
	for(i=1;i<=n;i++)
	{
		document.write("<br>");
		for(j=1;j>=i;j++)
		{
			document.write("*");
		}
		}
</script>
</body>
</html>

推荐答案

再考虑一下。



1.你喜欢将限制中的星星打印到一个

2.赋予变量代表名称有时会帮助很多



所以让我们来看看循环。首先,我们需要从限制计算到一个:



Think about it again.

1. You like to print stars from limit down to one
2. Giving variables representative names helps sometimes a lot

So let's have a look to the loops. First, we need to count from limit down to one:

// Outer Loop, which does control the column length
for (noOfColumns= limit; noOfColumns >=1; noOfColumns--)
{
   // here we have noOfColumns which means how many "*" we Need to print. 
   // So lets print from 1 to columns
   for (j= 1; j <= noOfcolumns; j++)
   {
      document.write("*");
   }
   // Current line is finished
   document.write("<br>"); 
}





我希望它有所帮助。请不要简单地复制和粘贴。试着理解它;)



I hope it helps. Please do not simply copy&paste. Try to understand it ;)


引用:

如何打印这个:



旅行代码给予

*

**

***

*** *

*****

你想要

*****

****

***

**

*

说不然,你有:

f(1)= 1,f(2)= 2,f(3)= 3,f(4)= 4,f(5)= 5

你想要

f(1)= 5,f(2)= 4,f(3)= 3,f(4)= 2,f(5)= 1

你不能设备公式pf f()?

这真的不复杂。


Tour code gives
*
**
***
****
*****
and you want
*****
****
***
**
*
Said otherwise, you have:
f(1)= 1, f(2)= 2, f(3)=3, f(4)= 4, f(5)= 5
and you want
f(1)= 5, f(2)= 4, f(3)=3, f(4)= 2, f(5)= 1
Can't you device the formula pf f() ?
It is really not complicated.


这篇关于如何打印:的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆