OpenText Interview Question

Write a program to count no of words in a string?

Interview Answers

Anonymous

Nov 20, 2015

Programes on structures and datastructures and some queries.

6

Anonymous

Aug 3, 2017

public class Wordcount{ public static void main(String[] args) { System.out.println("enter string"); Scanner sc= new Scanner(System.in); String in = sc.nextLine(); String[] str = in.split("\\s"); int size = str.length; System.out.println(size); }

1