Wednesday, 4 May 2022

Check vowels in String

 

Problem statement: 

      Please check whether vowels present in the given String or not

Sample input1: india

Sample output1: Vowels present in the String

Sample input2: bbc

Sample output2: Vowels not present in the string

     

Solution:

        public void checkVowelsInString() {

System.out.println("checkVowelsInString:");

System.out.println("-----------------------");

String input="sssss";

if(input.matches(".*[aeiou].*")) {

System.out.println("Vowels present in string");

}

else {

System.out.println("Vowels not present in string");

}

System.out.println("==============================================\n\n");

}


Output: Vowels not present in the string


No comments:

Post a Comment

Switch case in Java

 Problem statement: Return the capital of a state based on input state          public String getCapital(String state){               switch...