Print First , Second , Third Character of Given String Using CharAt() method
Question:
Write a Java program to print the First,Second and Thrid Character of given String.
Input: "Selenium Testing Tool"
Output: "STTeeolso"
Steps:
Step 1: Initialize the input string
Step 2: Create findChar() method
Step 3: Split the Given String using split() method
Step 4: Iterate the for loop to print the expected characters by using charAt() method
Step 5: Execute the Program
public class PrintFirstSecondCharOfString {
public static void main(String[] args) {
String input1 = "Selenium Testing Tool";
findChar(input1);
}
public static void findChar(String input){
String[] arrStr = input.split(" ");
//Logic to print the First , second,thrid Character of string
for(int i=0;i<arrStr.length;i++){
for(int j=0;j<arrStr.length;j++){
char firstWord = arrStr[j].charAt(i);
System.out.print(firstWord);
}
}
}
}
Output:
STTeeolso
Comments
Post a Comment