我们有练习
确定并打印99元素浮点数组w
中包含的最小值和最大值。
解决方案是:
var highestNumber = w[ 0 ];
var lowestNumber = w[ 0 ];
for ( var i = 1; i < 99; i++ )
{
if ( w[ i ] > highestNumber )
highestNumber = w[ i ];
if ( w[ i ] < lowestNumber )
lowestNumber = w[ i ];
}
document.writeln( highestNumber + " " + lowestNumber );
此处字符串连接" "
的目的是什么?
答案 0 :(得分:1)
" "
在字符串中创建一个空格,所以它看起来像这样:
document.writeln( X + " " + Y );
X Y
而不是
document.writeln( X + Y );
XY
答案 1 :(得分:0)
" "
会在给定的最高值和最低值之间提供空格。与此99 85
相同,否则会显示为9985
highestNumber = 99;
lowestNumber = 85;
示例:
document.writeln( highestNumber + " " + lowestNumber );
OutPut:
99 85