*i. - This program asks you to input a sentence and counts the number of * letters and words in the sentence. * */
public class CountSentence{ public static void main(String[] args) { Scanner scan = new Scanner(System.in); String sentence = ""; int words = 0; int letters = 0; int index = 0;
/** ADD CODE HERE
1. Ask the user to input a sentence assuming the sentence ends with a full stop/period (and also assume that there are only letters (a - z) and spaces in the sentence - no numbers).
2. Loop while the current character in the sentence is not equal to a full stop/period. 2.1 If current character is a letter then add 1 to the number of letters otherwise character is a space and so 1 can be added to the number of words. Make sure you move past any spaces to start at next word. */
System.out.println("The number of words are " + words); System.out.println("The number of letters are " + letters); }}
Already registered? Login
Not Account? Sign up
Enter your email address to reset your password
Back to Login? Click here