Home > Web Front-end > JS Tutorial > body text

Detailed explanation and implementation code of judging palindrome number in javascript

高洛峰
Release: 2017-02-03 13:49:26
Original
1425 people have browsed it

javascriptJudge the number of palindromes

Summary:

Palindrome refers to a sentence that can be read both forward and backward. It is a rhetorical method and text that has been used in ancient and modern times, both at home and abroad. Games, such as "I am for everyone, everyone is for me", etc. In mathematics, there is also a type of number with such characteristics, called palindrome number (palindrome number) Let n be. An arbitrary natural number. If the natural number n1 obtained by reversing the digits of n is equal to n, then n is called a palindrome number. For example, if n=1234321, n is called a palindrome number; but if n=1234567. , then n is not a palindrome number

Note:

1. Even numbers also have palindrome numbers 124421
2. There are no palindrome numbers for decimals

Implementation code:

<html> 
  <head> 
    <meta http-equiv="Content-Type" content="text/html;charset=gb2312"/> 
    <title>test</title> 
    <script type="text/javascript"> 
      var number = parseInt(window.prompt("输入回文数")); 
      if(daozhi(number) == number) { 
        document.writeln(number + "是回文数"); 
      } else { 
        document.writeln(number + "不是回文数");  
      } 
        
      /*整数的倒置*/
      function daozhi(num) { 
        var newNumber = 0; 
          
        while(num != 0) { 
          newNumber *= 10; 
          newNumber =newNumber + (num % 10); 
          num = Math.floor(num/10); 
        } 
          
        return newNumber; 
      } 
        
    </script> 
  </head> 
  <body> 
  </body> 
</html>
Copy after login

Thank you for reading, I hope it can help everyone, thank you for your support of this site!

More details about javascript judgment palindrome number and implementation code related Please pay attention to PHP Chinese website

for articles!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!