1 js中的for循环,实心菱形,空心菱形,九九乘法表,等腰三角形 /* * 2 * * 3 * * * 4 * * 5 * 6 */ 7 8 //实心菱形 9 10 var count=3; 11 for (var i=1;i<=count ;i++ ) 12 { 13 for (var k=3;k>=i ;k-- ) 14 { 15 document.write(" "); 16 } 17 for (var j=1;j<=i ;j++) 18 { 19 document.write("*"+" "); 20 } 21 document.write("</br>"); 22 } 23 for (var k=2;k>0 ;k-- ) 24 { 25 for (var n=3;n>=k ;n-- ) 26 { 27 document.write(" "); 28 } 29 for (var m=1;m<=k ; m++ ) 30 { 31 document.write("*"+" "); 32 } 33 document.write("</br>"); 34 } 35 36 //空心菱形 37 var count=3 38 for (var i=1; i<=count;i++ ) 39 { 40 for (var k=2;k>=i ;k-- ) 41 { 42 document.write(" "); 43 } 44 45 for (var j=1;j<=2*i-1 ;j++ ) 46 { 47 if (j==1 || j==2*i-1) 48 { 49 document.write("*"); 50 } 51 else{ 52 document.write(" "); 53 } 54 } 55 document.write("</br>"); 56 } 57 //空心菱形的下半部分 58 for (var i=1;i<count ;i++ ) 59 { 60 for (var k=1;k<=i ;k++ ) 61 { 62 document.write(" "); 63 } 64 for (var j=1;j<=2*count-3 ;j++ ) 65 { 66 if (j==1 || j==(2*count-1)-2*i) 67 { 68 document.write("*"); 69 } 70 else{ 71 document.write(" "); 72 } 73 } 74 document.write("</br>"); 75 } 76 77 //等腰三角形 78 79 var count=3; 80 for (var i=1;i<=count ;i++ ) 81 { 82 for (var k=2;k>=i ;k-- ) 83 { 84 document.write(" "); 85 } 86 for ( var j=1;j<=i; j++) 87 { 88 document.write("*"+" "); 89 } 90 document.write("</br>"); 91 } 92 93 //九九乘法表 94 95 for (var i=1;i<=9 ;i++ ) 96 { 97 for (var j=1;j<=i ;j++ ) 98 { 99 document.write(i+"*"+j+"="+(i*j)+" "+((i*j)<10?" ":"")); 100 } 101 document.write("</br>"); 102 } //另一种九九 103 for (var i=9;i>=1 ;i-- ) 104 { 105 for (var j=1;j<=i ;j++ ) 106 { 107 document.write(i+"*"+j+"="+(i*j)+" "+((i*j)<10?" ":"")); 108 } 109 document.write("</br>"); 110 }
时间: 2024-11-18 12:17:42