Answers for "java program to read user input of a palindrome"

6

easy palindrome program in java

import java.util.*;   
class PalindromeExample2  
{  
   public static void main(String args[])  
   {  
      String original, reverse = ""; // Objects of String class  
      Scanner in = new Scanner(System.in);   
      System.out.println("Enter a string/number to check if it is a palindrome");  
      original = in.nextLine();   
      int length = original.length();   
      for ( int i = length - 1; i >= 0; i-- )  
         reverse = reverse + original.charAt(i);  
      if (original.equals(reverse))  
         System.out.println("Entered string/number is a palindrome.");  
      else  
         System.out.println("Entered string/number isn't a palindrome.");   
   }  
}
Posted by: Guest on August-28-2020
0

Palindrome string program in java using scanner

class Main
{
public static void main(String args[])
{
String a, b = "";
Scanner in = new Scanner(System.in);
System.out.println("Enter the string");
a = in.nextLine();
int length = a.length();
for (int i = length - 1; i >= 0; i--)
b = b + a.charAt(i);
if(a.equals(b))
System.out.println("The string is a palindrome.");
else
System.out.println("The string is not a palindrome.");
}
}
Posted by: Guest on June-12-2021

Code answers related to "java program to read user input of a palindrome"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language