JavaScript:有没有办法不换行打印输出?

JavaScript:有没有办法不换行打印输出?,javascript,rhino,Javascript,Rhino,我正在学习JavaScript,并试图打印这一特定的哈希序列: # ## ### 我编写了这段代码来生成序列: for(let i = 0; i < 3; i++){ for(let j = 0; j <= i; j++){ print('#'); } print('\n'); } 我使用此程序获得正确的输出: var starString = ""; for(let i = 0; i < 3; i++){ for(let j

我正在学习JavaScript,并试图打印这一特定的哈希序列:

#
##
###
我编写了这段代码来生成序列:

for(let i = 0; i < 3; i++){
    for(let j = 0; j <= i; j++){
        print('#');
    }
    print('\n');
}
我使用此程序获得正确的输出:

var starString = "";
for(let i = 0; i < 3; i++){
    for(let j = 0; j <= i; j++){
        starString += '#';
    }
    print(starString);
    starString = "";
}
var starString=“”;
for(设i=0;i<3;i++){

对于(设j=0;jNo,不直接使用
print()
。但是,您可以使用打印时不使用新行的
System.out.print()
来创建自己的函数:

function printNOn(arg) {
     java.lang.System.out.print(arg)
}
结果:

MBP:rhino1_7R4 mark$ java -jar js.jar
Rhino 1.7 release 4 2012 06 18
js> function printNOn(arg) {
     java.lang.System.out.print(arg)
} 
js> for(let i = 0; i < 3; i++){
  >     for(let j = 0; j <= i; j++){
  >         printNOn("#")
  >     }
  >     printNOn('\n')
  > }
#
##
###
js>
MBP:rhino1_7R4标记$java-jar js.jar
Rhino 1.7版本4 2012 06 18
js>函数printNOn(arg){
java.lang.System.out.print(arg)
} 
js>for(设i=0;i<3;i++){
>对于(设j=0;j printNOn(“#”)
>     }
>printNOn('\n')
> }
#
##
###
js>
console.log('Node js-hello world');
用于(变量计数器=0;计数器<5;计数器++){
//控制台日志(“------------------------------”);
变量pound=“#””;
对于(var localcounter=0;localcounter
function printNOn(arg) {
     java.lang.System.out.print(arg)
}
MBP:rhino1_7R4 mark$ java -jar js.jar
Rhino 1.7 release 4 2012 06 18
js> function printNOn(arg) {
     java.lang.System.out.print(arg)
} 
js> for(let i = 0; i < 3; i++){
  >     for(let j = 0; j <= i; j++){
  >         printNOn("#")
  >     }
  >     printNOn('\n')
  > }
#
##
###
js>
console.log('Node js - hello world');
for(var counter = 0; counter< 5 ;counter++){
    // console.log("----------------");
    var pound = "#";
    for(var localcounter = 0; localcounter < counter; localcounter++ ){

      //console.log("localcounter is ", localcounter);
       //console.log("counter is ", counter);
      //console.log(pound);
      pound += "#";
      //console.log(pound);
    }
    console.log(pound);
    //console.log("----------------");

    //
    pound = "";
    pound = null;
}