String Splitting and counting the number ocurances of a word in given string

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Arunkumar6966
    New Member
    • Apr 2014
    • 1

    String Splitting and counting the number ocurances of a word in given string

    Java Assignment:
    Input String: "Welcome to India Welcome to Pune Welcome to Mumbai"
    Output should be as follows:
    ------------output 1----------
    Welcome = 3
    to = 3
    India = 1
    Pune = 1
    Mumbai = 1
    ------------output 2----------
    Welcome Welcome Welcome
    to to to
    India
    Pune
    Mumbai
  • techboy
    New Member
    • Apr 2014
    • 28

    #2
    Its simple you can use split() which will split all words with spaces and then using that string array you can count the words as well as print them.

    refer:http://docs.oracle.com/javase/7/docs...va.lang.String)
    Last edited by Niheel; Apr 15 '14, 02:17 PM. Reason: fixed spacing

    Comment

    Working...