- To check string is Palindrome or not
User Input: "aabbaa"
Output: Palindrome String
import java.util.Scanner
fun main(args: Array<String>) {
print("Enter your string : ")
val userInput = Scanner(System.`in`)
var s1:String
var reverse:String=""
s1=userInput.nextLine()
var l:Int=s1.length-1
while(l!=-1) {
reverse+=s1[l--];
}
if(s1==reverse)println("Palindrome String");
else println("Not a Palindrome String");
}
Enter Your string : noon Palindrome StringProgram
You must know first,
Palindrome String : if a string & reverse of it are equal then the string is Palindrome string
Example :
String: "aba" & its Reverse = "aba" . so it's Palindrome String: "abc" & its Reverse = "cba" . so it's NOT a Palindrome
//reverse the string
int l=s1.length-1;
while(l!=-1) {
reverse+=s1[l--];
}
//check for the Palindrome
if(s1==reverse)
Concept
Coming Soon !
QuickIn order to succeed you must fail, so that you know what not to do the next time.