Answer to Question #63823 in Java | JSP | JSF for lama

Question #63823
method shortestWord () that does not accept any parameter and return string these metode should find the shortest word in sentence
please help me in me in my homewoork
1
Expert's answer
2016-12-06T14:34:10-0500
package question63823;

import java.util.*;

public class Question63823 {

static String sentence;

public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
sentence = sc.nextLine();
System.out.println(shortestWord());
}

public static String shortestWord() {
String[] arrayOfWord = sentence.split(" ");
int minLength = Integer.MAX_VALUE;
String result = null;
for (String word : arrayOfWord) {
int tempLength = word.length();
if (tempLength < minLength && word.length() > 0 && Character.isAlphabetic(word.charAt(0))) {
minLength = tempLength;
result = word;
}
}
return result;
}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS