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
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;
}
}