例:输入几个整数,最终以从小到大的方式输出。(js)

 

我们假设输入三个数,x、y、z

var x = prompt("请输入第一个数")
var y = prompt("请输入第二个数")
var z = prompt("请输入第三个数")

var x = parseInt(x)
var y = parseInt(y)
var z = parseInt(z)

if(x alert(x + "," + y + "," + z )
}
if(x < z && z < y){
alert(x + "," + z + "," + y )
}
if(y < x && x < z){
alert(y + "," + x + "," + z )
}
if(y < z && z < x){
alert(y + "," + z + "," + x )
}
if(z < x && x < y){
alert(z + "," + x + "," + y )
}
if(z < y && y < x){
alert(z + "," + x + "," + y )
}

转载于:https://www.cnblogs.com/little-rock/p/7402058.html

你可能感兴趣的:(例:输入几个整数,最终以从小到大的方式输出。(js))