can someone help me understand what each part of this code is doing public static String getLongestSentence() throws Fi
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am
can someone help me understand what each part of this code is doing public static String getLongestSentence() throws Fi
can someone help me understand what each part of this code is doingpublic static String getLongestSentence() throws FileNotFoundException { int numWords = 0; String longestSentence = ""; String currentSentence = ""; Scanner scan = new Scanner(new File("t1.txt")); while (scan.hasNext()) { currentSentence = getNextSentence(scan); if (currentSentence.length() > longestSentence.length()) { longestSentence = currentSentence; } } scan.close(); String[] wordList = longestSentence.split("\\s+"); numWords += wordList.length; System.out.println(longestSentence); System.out.println("Number of words in this sentence: " + numWords); return longestSentence;}