Answers for "what is palindrome number"

1

palindrome number in java

import java.util.Scanner;

public class Palindrome
{
  public static void main(String args[])
  {
    int num,temp,reverse=0;
    Scanner input=new Scanner(System.in);
    num=in.nextInt();
    temp=num;
    //code to reverse the number
    while(temp!=0)
    {
      int d=temp%10; //extracts digit at the end
      reverse=reverse*10+d;
      temp/=10; //removes the digit at the end
    }
    // 'reverse' has the reverse version of the actual input, so we check
    if(reverse==num)
    {
      System.out.println("Number is palindrome");
    }
    else
    {
      System.out.println("Number is not palindrome");
    }
  }
}
Posted by: Guest on August-20-2020
0

determine whether integer is a palindrome

public class Solution {
    public bool IsPalindrome(int x) {
        if(x < 0 || (x % 10 == 0 && x != 0)) {
            return false;
        }

        int revertedNumber = 0;
        while(x > revertedNumber) {
            revertedNumber = revertedNumber * 10 + x % 10;
            x /= 10;
        }

        return x == revertedNumber || x == revertedNumber/10;
    }
}
Posted by: Guest on June-18-2020
1

palindrome number

while(n>0){    
   r=n%10;  //getting remainder  
   sum=(sum*10)+r;    
   n=n/10;    
  }
Posted by: Guest on June-08-2021
0

what is palindrome

function Palindrome(str) { 

  str = str.replace(/ /g,"").toLowerCase();
  var compareStr = str.split("").reverse().join("");

  if (compareStr === str) {
    return true;
  } 
  else {
    return false;
  } 

}
Posted by: Guest on June-17-2021
0

Finding palindrome numbers

//Finding palindrome numbers

// first convert to string (slow)
fn is_palindrome1(num: i32) -> bool {
    return num.to_string().chars().rev().collect::<String>() == num.to_string();
}

// variation using zip
fn is_palindrome2(num: i32) -> bool {
    let s = num.to_string();
    for (i1, i2) in s.chars().zip(s.chars().rev()) {
        if i1 != i2 {
            return false;
        }
    }
    return true;
}

// divide by 10 (fast)
fn is_palindrome3(num: i32) -> bool {
    let mut reversed = 0;
    let mut number = num;
    while number > 0 {
        reversed = reversed * 10 + number % 10;
        number = number / 10;
    }
    return reversed == num || num == number / 10;
}

fn main() {
    for i in 700..750 {
        if is_palindrome1(i) {
            println!("Pal1: {}", i);
        }
        if is_palindrome2(i) {
            println!("Pal2: {}", i);
        }        
        if is_palindrome3(i) {
            println!("Pal3: {}", i);
        }
    }
}
Posted by: Guest on September-06-2021
0

check palindrome

bool isPlaindrome(string s)
	{
	   int i=0;
	   int j=s.length()-1;
	   while(i<j)
	   {
	       if(s[i]==s[j])
	       {i++;
	   j--;}
	   else break;
	   }
	   if (i==j || i>j) return 1;
	   else return 0;
	}
Posted by: Guest on October-23-2020

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language