Submission
Due Dates
The input will be a sentence. Your program has to output a listing of the number of words of length = 1, number of words of length = 2 and so on. You can assume that the maximum length of the words in your input sentence will not be more than 10.
import java.util.Scanner;
public class Word_Count {
public static void main(String[] args) {
System.out.println("Word Length – Frequency Count");
Scanner scanner = new Scanner(System.in);
System.out.println("Input Your Sentence");
String sentence = scanner.nextLine();
String delimiter = "[? ,!.;]+"; // multiple occurrences of ?,!.; are
// treated as delimiters between words
String[] words = sentence.split(delimiter); // The split method returns a
// string array which contains
// the individual words of the
// sentence
int a[] = new int[11]; // assuming that the largest word in the
// input will have a length of 10
// Your code here
}
}
> to be or not to be
Words of Length 1 = 0
Words of Length 2 = 5
Words of Length 3 = 1
Words of Length 4 = 0
Words of Length 5 = 0
Words of Length 6 = 0
Words of Length 7 = 0
Words of Length 8 = 0
Words of Length 9 = 0
Words of Length 10 = 0
The input to your program will be a sentence. Your program has to output the longest word in the sentence whose letters are distinct. If there is tie, pick any one. If the input sentence has no word with distinct letters, say “No such word”. Your program should treat uppercase and lowercase letters identically.
import java.util.Scanner;
public class Longest_Distinct_Word {
public static boolean has_distinct_letters(String input) {
// Your code here
}
public static void main(String[] args) {
System.out.println("Program to find the longest word with distinct letters:");
Scanner scanner = new Scanner(System.in);
System.out.println("Input your sentence");
String sentence = scanner.nextLine();
String delimiter = "[! ,.?]+";
String[] words = sentence.split(delimiter);
// Your code here
}
}
> It was a fine day
fine
> Animation! Multimedia!
No such word