Posts

Showing posts from September, 2023

Java Program to Check Palindrome Number

c lass PalindromeNumber {   public static void main(String[] args )   {         int num = 755, reversedNum = 0, remainder ;         // store the number to originalNum     int originalNum = num ;         // get the reverse of originalNum     // store it in variable     while ( num != 0) {       remainder = num % 10;       reversedNum = reversedNum * 10 + remainder ;       num /= 10;     }         // check if reversedNum and originalNum are equal     if ( originalNum == reversedNum ) {       System. out .println( originalNum + " is Palindrome." );     }     else {       System....

Java Program to Check Palindrome String

c lass PalindromeString { public static void main(String[] args ) { String str = "darga" , reverseStr = "" ; int strLength = str .length(); for ( int i = ( strLength - 1); i >=0; -- i ) { reverseStr = reverseStr + str .charAt( i ); } if ( str .toLowerCase().equals( reverseStr .toLowerCase())) { System. out .println( str + " is a Palindrome String." ); } else { System. out .println( str + " is not a Palindrome String." ); } } } Output :  darga is not a Palindrome String. Explanation : 1. class PalindromeString: 2. This is a Java class named "PalindromeString." 3. public static void main(String[] args): 4. This is the main method where the program starts executing. 5. String str = "darga", reverseStr = "";: 6. It initializes two strings, str...