Answer to Question #111641 in Java | JSP | JSF for Austin

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
1
Expert's answer
2020-04-24T11:33:31-0400
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!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS