用javascript输出如下数列

来源:百度知道 编辑:UC知道 时间:2024/06/03 10:37:04
如题。输出第一行是1,第二行是1 2,第三行1 2 3,一直到第n行1 2 3 4 5 6 7 8 9 10,请诸位不吝赐教。

如下:

<script>
var str = "";
for(i=1; i<=10; i++)
{
str += i + " ";
document.write(str+"<br />");
}
</script>

lnlb999 写的就安全正确了~~我就不再写了~~

public class Trybu {

public static void main(String[] args) {

StringBuffer buff = new StringBuffer();
for( int i = 1; i <= 10; i++)
{
buff.append(i);
buff.append(" "); // 输入空格
System.out.println( buff );
}

}
}

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">