Answers for "palindrome strings in java"

6

Java program to check whether string is palindrome using library methods

public class StringPalindromeJava
{
   public static void isPalindrome(String str)
   {
      String strReverse = new StringBuffer(str).reverse().toString();
       // checking for palindrome
      if(str.equals(strReverse))
      {
         System.out.println(str + " is palindrome string.");
      }
      else
      {
         System.out.println(str + " is not palindrome string.");
      }
   }
   public static void main(String[] args)
   {
      // palindrome java
      isPalindrome("eye");
      isPalindrome("rotator");
   }
}
Posted by: Guest on November-02-2020
0

palindrome in java

public class PlaindromeTest1 {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
System.out.println("Enter your words"); // Whats up body? // ?ydob pu stahW
        String word = input.nextLine();

        String reversedWord = "";
        // start from last index number.
        for(int i = word.length()-1; i>=0; i-- ){
           reversedWord += word.charAt(i);
        }
        System.out.println(reversedWord);
        //Level ==> leveL //ey edip adanada pide ye :)
        boolean palindrome = word.equalsIgnoreCase(reversedWord);

        System.out.println(palindrome);

        String str = "Anna";
        String result = "";

        for(int i = str.length()-1; i>=0; i-- ){
            result += str.substring(i, i+1);
            // result += str.charAt(i); // char at de olur
        }
        boolean result1 = str.equalsIgnoreCase(result);
        System.out.println(result1);
    }
Posted by: Guest on June-04-2021
0

palindrome in java

package com.candidjava; import java.util.Scanner; public class PalindromeUptoN{	public static void main(String[] args)	{		int n, b, rev = 0;		Scanner sc = new Scanner(System.in);		System.out.println("Enter the Palindrome No N:");		int N = sc.nextInt();		System.out.print("Palindrome numbers from 1 to N:");		for (int i = 1; i <= N; i++)		{			n = i;			while (n > 0)			{				b = n % 10;				rev = rev * 10 + b;				n = n / 10;			}			if (rev == i)			{				System.out.print(i + " ");			}			rev = 0;		}	} }
Posted by: Guest on May-27-2021

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language