Multiplication
// For (I = 1; I <= 9; I ++) {// control row
// For (j = 1; j <= I; j ++) {// Control
// Document. write (I + "*" + j + "=" + (I * j) + "& nbsp ");
//}
// Document. write ("<br/> ");
//}
/*
*
***
*****
*/
// For (I = 1; I <= 5; I ++) {// control row
// For (j = 1; j <= 2 * I-1; j ++) {// Control
// Document. write ("*");
//}
// Document. write ("<br/> ");
//}
/*
*
***
*****
*******
*********
***********
*************
***************
*****************
*******************
*/
// For (I = 1; I <= 10; I ++ ){
//// Print space
// For (t = 1; t <= 10-I; t ++ ){
// Document. write ("& nbsp ");
//}
// For (j = 1; j <= 2 * I-1; j ++ ){
// Document. write ("*");
//}
// Document. write ("<br/> ");
//}
// Print the diamond Graph
// For (I = 1; I <= 5; I ++ ){
//// Print space
// For (t = 1; t <= 5-i; t ++ ){
// Document. write ("& nbsp ");
//}
// For (j = 1; j <= 2 * I-1; j ++ ){
// Document. write ("*");
//}
// Document. write ("<br/> ");
//}
/*
Number of rows, number of stars, number of spaces
*/
For (I = 4; I> = 1; I --){
// For (t = 4; t> = I; t --)
For (t = 5-i; t> = 1; t --)
{
Document. write ("& nbsp ;");
}
For (j = 1; j <= 2 * I-1; j ++ ){
Document. write ("*");
}
Document. write ("<br/> ");
}
You can use the for loop to implement some related images.
For example, print the diamond:
*
***
*****
*******
*********
*******
*****
***
*
// Print the diamond Graph
For (I = 1; I <= 5; I ++ ){
// Print space
For (t = 1; t <= 5-i; t ++ ){
Document. write ("& nbsp ");
}
For (j = 1; j <= 2 * I-1; j ++ ){
Document. write ("*");
}
Document. write ("<br/> ");
}
/*
Number of rows, number of stars, number of spaces
*/
For (I = 4; I> = 1; I --){
// For (t = 4; t> = I; t --)
For (t = 5-i; t> = 1; t --)
{
Document. write ("& nbsp ;");
}
For (j = 1; j <= 2 * I-1; j ++ ){
Document. write ("*");
}
Document. write ("<br/> ");
}
/*
*
**
**
**
*****
*/
For (I = 1; I <= 5; I ++)
{
// Print space
For (t = 1; t <= 5-i; t ++)
{
Document. write ("& nbsp ;");
}
For (j = 1; j <= 2 * I-1; j ++)
{
// Print other rows except the last row, with spaces in the first and last columns.
If (I <5)
{
If (j = 1 | j = 2 * i-1)
Document. write ("*");
Else
Document. write ("& nbsp ;");
}
Else // last line, odd *, even space
{
If (j % 2! = 0)
Document. write ("*");
Else
Document. write ("& nbsp ;");
}
}
Document. write ("<br/> ");
}
<! DOCTYPE html PUBLIC "-// W3C // DTDXHTML 1.0 Transitional //" http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312"/>
<Title> triangle printing </title>
</Head>
<Body style = "text-align: center;">
<Script type = "text/javascript">
Var k = prompt ("Enter the number of printed rows :","");
For (var I = 1; I <= k; I ++)
{
For (varj = 0; j <I; j ++)
{
Document. write ("* & nbsp ;");
}
Document. write ("<br/> ");
}
</Script>
</Body>
</Html>
From Aweijun360