Check if letters that a word consists of are present in another string

后端 未结 3 918
后悔当初
后悔当初 2021-01-29 07:35

This is my first time posting here, so please tell me if I need to correct anything in this post. I\'d like to ask for help with something that\'s been giving me some trouble.

3条回答
  •  我在风中等你
    2021-01-29 08:02

    It is returning true because your testing one char of randomString

    public static boolean Checkword( String pattern, String randomString ){
      return ( randomString .contains( pattern ) ) ? true : false;
    }
    
    String pattern = "LABEL";
    
    String randomString = "BFEABLDEG";
    Checkword( pattern, randomString );
    //return false
    
    randomString = "AZDAZLABELIIDZA";
    Checkword( pattern, randomString );
    //return true
    

提交回复
热议问题