Write a Java program that receives a string representing a sentence. Your program should find the longest word in the sentence and print it out. Assume that the words in the sentence are separated by a single space and there are no punctuation marks.
Processing strings
Finding the longest word in a sentence
Report a typo
Sample Input 1:
This is a sample sentenceSample Output 1:
sentenceSample Input 2:
Java is a powerful languageSample Output 2:
powerfulWrite a program in Java 17
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String sentence = scanner.nextLine();
// Your code here
}
}
Create a free account to access the full topic
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.