倒三角:
方法一:
let readline = require("readline-sync"); console.log("请输入行数"); let line = readline.question(""); let c =""; let d =""; let f =""; for(let i =line;i>=1;i--){ for(let j =line-i;j>=1;j--){ c +=" "; } for(let k =2*i-1; k>=1; k--){ d +="*"; } f = c+d; console.log(f); c =""; d =""; f =""; }
效果:
正三角
let read=require("readline-sync") console.log("请输入个数字") let num=read.question("") let kg=""//空格 let xx ="" //星星* let link ="" //打印 for(var i=1;i<=num;i++){ for(var j=1;j<=num-i;j++){ //控制空格数 kg+=" " } for(var k=1;k<=2*i-1;k++){ //控制*的数量 xx+="*" } link=kg + xx; console.log(link) link="" kg="" xx="" }
效果:
原文地址:https://www.cnblogs.com/gao7/p/11119040.html
时间: 2024-11-12 14:54:13