Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class PalindromeTest {
- public static void main(String args[]){
- Scanner scan =new Scanner(System.in);
- String test =scan.nextLine();
- int palindrome = Integer.parseInt(scan.nextLine());
- while(!test.equals("END")){
- if(isPalindrome(palindrome)){
- System.out.println("true");
- }else{
- System.out.println("false");
- }
- test =scan.nextLine();
- }
- }
- /*
- * Java method to check if a number is palindrome or not
- */
- public static boolean isPalindrome(int number) {
- int palindrome = number; // copied number into variable
- int reverse = 0;
- while (palindrome != 0) {
- int remainder = palindrome % 10;
- reverse = reverse * 10 + remainder;
- palindrome = palindrome / 10;
- }
- // if original and the reverse of number is equal means
- // number is palindrome in Java
- if (number == reverse) {
- return true;
- }
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement