Palindromes in Java

I need to create a program that asks to write strings , and ends when i type the word "END".

Then it tells how many strings i typed

and how many of them were palindromes

they are a word, phrase, or sequence that reads the same backward as forward

like

AKA , RAMUSH AGA SHUMAR , etc

it has to be with a do while loop

and the testing if it is a palindrome or not should be made with a static method

called itsPalindrome.

Comments

  • class PalindromeExample{  
     public static void main(String args[]){  
      int r,sum=0,temp;    
      int n=454;//It is the number variable to be checked for palindrome  
    
      temp=n;    
      while(n>0){    
       r=n%10;  //getting remainder  
       sum=(sum*10)+r;    
       n=n/10;    
      }    
      if(temp==sum)    
       System.out.println("palindrome number ");    
      else    
       System.out.println("not palindrome");    
    }  
    }  
    

    Output:

    imagepalindrome number" alt="" />

    To learn Java visit https://hackr.io/tutorials/learn-java

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion