小说网站 搜小说 无限网 烟雨红尘 小说爱好者 免费小说 免费小说网站

javascript语法之循环语句小练习

<!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">
<head>
<script type="text/javascript"> 
//需求1:显示"*"为正方形,5行5列。
	
	for(var i = 0 ; i<5;  i++){ // 控制行数
		for(var j  = 0 ; j<5 ; j++){ //控制列数
			document.write("* ");	
		}	
		//换行
		document.write("<br/>")
	}
	
	document.write("<hr/>")
 
/*
输出一个直角三角形
 
*
**
***
****
*****
 
*/
	
	for(var i = 0 ; i<5; i++){
		
		for(var j  =0 ; j<=i ; j++){
			document.write("* ");	
		}	
		document.write("<br/>");
	}
 
	document.write("<hr/>")
 
 
//打印九九乘法表
	for(var i = 1 ; i<= 9 ; i++){
		for(var j = 1 ; j<=i ; j++){
			document.write(j+"*"+i+"="+(i*j)+"  ");	
		}	
		document.write("<br/>");
	}
	
 
 
</script>
 
 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
 
<body>
</body>
</html>

posted on 2016-05-22 20:46  王小航  阅读(115)  评论(0编辑  收藏  举报

导航