String With Most Vowels

 Coding Problem Keys 

 String With Most Vowels 

 Problem Statement 

Two Strings S1 and S2 are given as input. The program must print the string with the most number of vowels. If two strings have the same number of vowels, print the string with greater length.

 Boundary Condition(s) 

1 <= Length of Strings <=1000

 Input Format 

The first line S1 and S2 separated by space(s).

 Output Format 

The first line contains a string.

 Example Input/Output 1 

 Input 

adder divider

 Output 

divider

 Example Input/Output 2 

 Input 

important welcome

 Output 

important

 Note: Max Execution Time Limit: 5000 millisecs 

 Solution 

 Programming Language: Java Language 

import java.util.*;
public class Hello {
    public static int vowel(String s){
        int x=0;
        s=s.toLowerCase();
        char ch;
        for(int i=0;i<s.length();i++){
            ch=s.charAt(i);
            if (ch=='a' || ch=='e' || ch=='i' || ch=='o' || ch=='u') x++;
        }return x;
    }
    public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		String s="", arr[]=sc.nextLine().split(" ");
		int mx=0,t;
		for(String a:arr){
		    t=vowel(a);
		    if (t>mx){
		        mx=t;s=a;
		    }else if (t==mx){
		        if (a.length()>=s.length()){
		            s=a;
		        }
		    }
		}System.out.print(s);
	}
}
// Published By PKJCODERS

 (Note: Incase If the code doesn't Pass the output kindly comment us with your feedback to help us improvise.) 

Comments

Popular Posts

Snakes and Ladders

Difference between a number and it's reverse

Reverse Column - First and Last

Matrix Diagonal Pattern

Sort integers in String

Find Co-ordinates - Other Side