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

Detailed explanation and implementation code for judging the number of palindromes in javascript (picture and text tutorial)

亚连
Release: 2018-05-19 11:43:06
Original
3767 people have browsed it

This article mainly introduces the detailed explanation and implementation code of javascript to determine the number of palindromes. Friends in need can refer to it

javascript to determine the number of palindromes

Summary:

"Palindrome" refers to a sentence that can be read both forward and backward. It is a rhetorical method and word game that has existed in ancient and modern times, both at home and abroad, such as "I am a human being" "People, everyone for me" etc. In mathematics, there is also a type of number with such characteristics, which is called a palindrome number.

Suppose n is an arbitrary natural number. If the digits of n are If the natural number n1 obtained by reverse arrangement is equal to n, then n is called a palindrome number. For example, if n=1234321, then n is called a palindrome number; but if n=1234567, then n is not a palindrome number.

Note:

1. Even numbers also have palindromes 124421
2. Decimals do not have palindromes

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

The above is what I compiled for everyone. I hope it will be helpful to everyone in the future.

Related articles:

Convert key-value string tojsonString steps detailed explanation

##p5.jsHow to implement and use mouse interaction

nodejsGenerate QR code (the simplest)

The above is the detailed content of Detailed explanation and implementation code for judging the number of palindromes in javascript (picture and text tutorial). For more information, please follow other related articles on the PHP Chinese website!

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!