Skip to content
This repository has been archived by the owner on Oct 14, 2021. It is now read-only.

Commit

Permalink
Created palindrome.java #456 (#521)
Browse files Browse the repository at this point in the history
The program checks both string and integer input from user
  • Loading branch information
KholoodS authored Oct 10, 2021
1 parent c4f7b84 commit 4b01d92
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions Programming/Java/Palindrome/palindrome.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.kholood;
import java.util.Scanner;
import java.lang.String;

public class palindrome {

public static void main(String [] args){

Scanner sc = new Scanner(System.in);
System.out.println("Enter the number: ");
String reverse = "";
String num = sc.nextLine();
int length = num.length();

for( int i = length - 1; i >= 0; i-- )
reverse = reverse + num.charAt(i);
if (num.equals(reverse))
System.out.println("The entered string " +num +" is a palindrome.");
else
System.out.println("The entered string " +num +" isn't a palindrome.");

System.out.print("Enter the string you want to check: ");
String original = sc.nextLine();
int n = original.length();
String reversestring="";
for(int i = n - 1; i >= 0; i--)
{
reversestring = reversestring + original.charAt(i);
}
if(original.equalsIgnoreCase(reversestring))
System.out.println("The string is palindrome.");
else
System.out.println("The string is not palindrome.");


}
}

0 comments on commit 4b01d92

Please sign in to comment.