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 check 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.

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.

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

Create a program in Java that will accept two integers. If the sum of the integers is odd, display the higher integer, else, display the lower integer.

Write a java program to accept a String and the perform the following operations:a) Count the number of words with the first and the last letter being same.

1/1

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.