Minimum Length Word

 

Given a string S (that can contain multiple words), you need to find the word which has minimum length.


Sample Input 1 :
this is test string
Sample Output 1 :
is
public class Solution {
	
	public static String minLengthWord(String input){
		String[] arr=input.split(" ");
        int i=0;
        int minlength;
        minlength=Integer.MAX_VALUE;
        String smallest;
        smallest = "";
        for(i=0;i<arr.length;i++)
        {
            
            if(arr[i].length() < minlength)
            {
                smallest=arr[i];
                minlength=arr[i].length();
            } 
        }
        return smallest;
    }
}

Comments

Popular posts from this blog

Check Number Sequence

Star Pattern