Advertisement
Guest User

Untitled

a guest
Jan 26th, 2020
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.  
  9. import java.util.Scanner;
  10. public class MyProgram
  11. {
  12. public static void main(String[] args){
  13. System.out.println("enter a sentence");
  14.  Scanner input = new Scanner(System.in);
  15.  String sentence = new String(input.nextLine());
  16.  System.out.println("enter a word that sentence may or may not contain");
  17.   String testString = new String(input.nextLine());
  18.   boolean bruhbool = containsWord(testString);
  19.  if(bruhbool == true){
  20.      System.out.println("the sentence contains that word");
  21.  }
  22.  if(bruhbool == false){
  23.      System.out.println("the sentence does not contain that word");
  24.  }
  25. }
  26. public static boolean containsWord (String str){
  27.     if(str.indexOf("disk") >= 0){
  28.         if(str.codePointAt(str.indexOf("disk")-1) != 32 || str.codePointAt(str.indexOf("disk")+4) != 0){
  29.             return false;
  30.         }
  31.         
  32.         return true;
  33.     }
  34. return false;
  35. }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement