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.  
  13. String[] words = {"GAGGAG", "AGGAC"};
  14. /*
  15. * GAGGAGGAC =
  16. * GAGGAG
  17. * AGGAC
  18. */
  19. String sentence = "GAGGAGGAC";
  20. if(checkContainsAll(sentence, words)) {
  21. System.out.println("The sentence " + sentence + " contains all words");
  22. } else {
  23. System.out.println("The sentence " + sentence +" does not contain all words.");
  24. }
  25.  
  26. sentence = "GAGGAGAGGAC";
  27. if(checkContainsAll(sentence, words)) {
  28. System.out.println("The sentence " + sentence + " contains all words");
  29. } else {
  30. System.out.println("The sentence " + sentence + " does not contain all words.");
  31. }
  32. }
  33.  
  34.  
  35.  
  36. public static boolean checkContainsAll(String sentence, String[] words) {
  37. for(String word : words) {
  38. if(!sentence.contains(word)) {
  39. return false;
  40. }
  41. sentence = sentence.replace(word, "");
  42. }
  43. return true;
  44. }
  45. }
Success #stdin #stdout 0.11s 321344KB
stdin
Standard input is empty
stdout
The sentence GAGGAGGAC does not contain all words.
The sentence GAGGAGAGGAC contains all words