can someone help me understand what each part of this code is doing public static String getLongestSentence() throws Fi

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
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

Post by answerhappygod »

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;}
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply