forked from aditya109/git-osp-for-beginners
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Created palindrome.java aditya109#456
The program checks both string and integer input from user
- Loading branch information
Showing
1 changed file
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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."); | ||
|
||
|
||
} | ||
} |