make selenium easy
Make Selenium Easy
Convert first character of each word into upper case.
Logic:
package StringPrograms; import java.util.Scanner; public class CapitaliseFirstCharOfWords { public static String CapitaliseCharOfWords(String sentence) { // Extract all words String words[] = sentence.split("\\s+"); // Creating an empty string of type StringBuilder so that modification of string is possible. StringBuilder sb = new StringBuilder(); // Iterating through words for (String word : words) { //Extracting first char char firstChar = word.charAt(0); // Checking if firstchar is not in upper case already if (!Character.isUpperCase(firstChar)) { // Convert first char into upper case and then append remaining characters of words. sb.append(Character.toUpperCase(firstChar)).append(word.substring(1)); } else sb.append(word.substring(0)); // Appending space after each word sb.append(" "); } // Converting StringBuilder to String. trim() is needed to trim last space appended. String result = sb.toString().trim(); return result; } public static void main(String[] args) { // User input for the string to know length Scanner sc = new Scanner(System.in); System.out.println("Please enter the string to Capitalize first char of each word:"); String userInput = sc.nextLine(); sc.close(); System.out.println("You entered: " + userInput); System.out.println("Output is :" + CapitaliseCharOfWords(userInput)); } }
Please enter the string to Capitalize first char of each word: make selenium easy You entered: make selenium easy Output is :Make Selenium Easy ============================================================= Please enter the string to Capitalize first char of each word: Make Selenium Easy You entered: Make Selenium Easy Output is :Make Selenium Easy ============================================================= Please enter the string to Capitalize first char of each word: make selenium easy 123 You entered: make selenium easy 123 Output is :Make Selenium Easy 123 ============================================================= Please enter the string to Capitalize first char of each word: make selenium easy &special You entered: make selenium easy &special Output is :Make Selenium Easy &special ============================================================= Please enter the string to Capitalize first char of each word: selenium You entered: selenium Output is :Selenium =============================================================
Note- A Java library named Apache Commons provides a class "WordUtils" provides method to achieve this. But in interview, it is expected to solve with logic instead of using built in methods.
#HappyCoding
My name is Amod Mahajan and I am an IT employee with 4+ years of experience in Software testing and staying in Bengaluru. My area of interest is Automation testing. I started from basics and went throw so many selenium tutorials. Thanks to Mukesh Otwani as his tutorials are easy and cover basics to advance. I have habit of exploring concepts by deep diving. I used to make notes. I thought of sharing my knowledge through posts and now I am here. #KeepLearning #ShareLearning
Hello Folks, There are two types of dependencies in TestNG: 1. Hard Dependency : All the methods you depend on must have…
Hello Folks, As part of our API Testing series, we will see “Installation of Postman Tool” in this post. Postman tool was…
Hello Folks, We have learnt in previous posts regarding establishing relationship between test methods. You can go through them below:…
"CamelCase" is a naming convention in which words are joined together without any whitespace in between and each word starts…
Hello Folks, Previously, I had published on Handling StaleElementReferenceException using PageFactory. But many people asked how to handle it if they…
Hello Guys, As I say always, your automation script is ineffective if you do not include logic to validate to…