fork(1) 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. String sentence = "GAGGAGGTC";
  15. if(checkContainsAll(sentence, words)) {
  16. System.out.println("The sentence " + sentence + " contains all words");
  17. } else {
  18. System.out.println("The sentence " + sentence +" does not contain all words.");
  19. }
  20.  
  21. sentence = "GAGGAGAGGAC";
  22. if(checkContainsAll(sentence, words)) {
  23. System.out.println("The sentence " + sentence + " contains all words");
  24. } else {
  25. System.out.println("The sentence " + sentence + " does not contain all words.");
  26. }
  27. }
  28.  
  29.  
  30.  
  31. public static boolean checkContainsAll(String sentence, String[] words) {
  32. for(String word : words) {
  33. if(!sentence.contains(word)) {
  34. return false;
  35. }
  36. }
  37. return true;
  38. }
  39. }
Success #stdin #stdout 0.1s 320320KB
stdin
Standard input is empty
stdout
The sentence GAGGAGGTC does not contain all words.
The sentence GAGGAGAGGAC contains all words