Knowee
Questions
Features
Study Tools

Write a program in java to accept a number and chech whether it is a palindrome number or not. Do the program without using modulus operator and String.

Question

Write a program in java to accept a number and chech whether it is a palindrome number or not. Do the program without using modulus operator and String.

🧐 Not the exact question you are looking for?Go ask a question

Solution

Sure, here is a Java program that checks if a number is a palindrome without using the modulus operator and String:

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("Enter a number: ");
        int num = scanner.nextInt();
        if (isPalindrome(num)) {
            System.out.println(num + " is a palindrome number.");
        } else {
            System.out.println(num + " is not a palindrome number.");
        }
    }

    public static boolean isPalindrome(int num) {
        int reversed = 0;
        int temp = num;
        while (temp != 0) {
            reversed = reversed * 10 + temp / 10;
            temp /= 10;
        }
        return num == reversed;
    }
}

This program works by reversing the number and then comparing the reversed number with the original number. If they are the same, then the number is a palindrome. The reversal is done by repeatedly dividing the number by 10 and adding the remainder to the reversed number.

This problem has been solved

Similar Questions

Write a C++ program to check if a given number is a palindrome. A palindrome is a number that remains the same when its digits are reversed.

Check Palindrome NumberWrite a program to check if the given number is a palindrome number.A palindrome number is a number that is the same after reverse. For example, 545, is the palindrome numbers

class Solution { public boolean isPalindrome(int x) { String num =Integer.toString(x); for(int i=num.length()-1;i<0;i--){ String a =" "+num; if(num==a){ System.out.println("it is palindrome:"+a); }else{ System.out.println("it is not palindrome:"+a); } } }}

Write a programme to check whether given input is palindrome or notConstraintsABC != PalindromeMAM == Palindrome123 != Palindrome151 == Palindrome

Write a Java program to check whether a given word is a palindrome or not. for e.g. MADAM is a palindrome but eat is not.

1/3

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.