Question #111641

Write a java programme that will counts all number of words in a sentence.The programme should have a minimum of two classes

Expert's answer

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        System.out.println("Input sentence");
        Scanner scanner = new Scanner(System.in);
        String s = scanner.nextLine();
        String[] strings = s.split(" ");
        System.out.println(strings.length + " words");

    }

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

LATEST TUTORIALS
APPROVED BY CLIENTS