一个5位数,判断它是不是回文数。即12321是回文数,个位与万位相同,十位与千位相同,用代码描述
作者:互联网
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<script>
var num=prompt("q请输入一个五位数")
console.log("输入数据的类型"+typeof num)
var len=num.length-1
console.log("输入字符串的下标最大值"+len)
var flag=true
console.log(flag)
for (var i=0;i<=len;i++){
console.log("num.charAt (i):"+num.charAt (i))
console.log("num.charAt (len-i):"+num.charAt (len-i))
if (num.charAt (i)!=num.charAt(len-i)){
flag=false
console.log(flag)
break
}
}
console.log(num)
alert("判断是否为回文数:"+flag)
</script>
</body>
</html>
标签:console,log,len,个位,flag,num,var,万位,回文 来源: https://blog.csdn.net/qq_57731353/article/details/122853898