fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. try{
  13. String sen = "hi hello hi good morning hello";
  14. String word[] = sen.split(" ");
  15. int count=0;
  16. for (int i = 0; i < word.length; i++) {
  17. count = 0;
  18. for (int j = 0; j < word.length; j++) {
  19. // System.out.println(word[i]+" "+word[j]);
  20. if (word[i].equals(word[j])) {
  21. count++;
  22. }
  23.  
  24. }
  25. if(count>1)
  26. System.out.println("the word " + word[i] + " occured " + count + " time");
  27. }
  28. }catch(Exception e){
  29. System.out.println(e);
  30. }
  31. }
  32. }
Success #stdin #stdout 0.09s 320576KB
stdin
Standard input is empty
stdout
the word hi occured 2 time
the word hello occured 2 time
the word hi occured 2 time
the word hello occured 2 time