Howdy, Stranger!

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

Categories

Palindromes in Java

Ajtan KolincAjtan Kolinc Member Posts: 2

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

  • Nihar MoreNihar More Member Posts: 3
    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.