Check whether string is palindrome – Selenium and Java challenge 8

*

I have provided a Selenium and Java program below to validate whether a given string is a palindrome. You can review the program and share your comments about its output. Click the “Click for Solution” button below to view the explanation.

import org.testng.annotations.Test;

public class SampleProgram8 {

@Test
public void testMySkills() {
   String str = "Test My Skill";
   if(checkPalindrome(str)){
    System.out.println("'"+str+"'"+" "+" is palindrome");
   }
   else{
     System.out.println("'"+str+"'"+" "+" is not palindrome");
   }
   
}

public Boolean checkPalindrome(String str) {
    int len = str.length();
    int start = 0;
    int end = len-1;
    while(start<=end) {
        if(str.charAt(start) != str.charAt(end)){
           return false;
        }
        start++;
        end--;
    }
    return true;
}

}

3 1 vote
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Testingtalkslatest.com - A project by CreativeHub IT Solutions.
Contact Us At: support@testingtalkslatest.com
Our Partner websites - Classified Hub , CodesToolbox , Smart Fitness Guide , CodesToolbox , Testing Forum
Scroll to Top
0
Would love your thoughts, please comment.x
()
x