Home  >  Article  >  Web Front-end  >  Detailed explanation and implementation code of judging palindrome number in javascript

Detailed explanation and implementation code of judging palindrome number in javascript

高洛峰
高洛峰Original
2017-02-03 13:49:261469browse

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>

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!

Statement:
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