codingbat java string 2 xyzthere

Solutions on MaxInterview for codingbat java string 2 xyzthere by the best coders in the world

showing results for - "codingbat java string 2 xyzthere"
Kenza
11 Feb 2019
1public boolean xyzThere(String str) {
2  int flag=0;
3  for(int i=0;i<str.length()-2;i++){
4    if (str.substring(i,i+2).compareTo("xy")==0 & str.substring(i+1,i+3).compareTo("yz")==0){
5      if ((i-1)>=0){
6        if (str.charAt(i-1)!='.'){
7          flag=1;
8          break;
9        }
10        else{
11          flag=0;
12        }
13      }
14      else{
15        flag=1;
16        break;
17        
18      }
19    }
20    else{
21      flag=0;
22    }
23  }
24  if (flag==0){
25    return false;
26  }
27  else{
28    return true;
29  }
30}
31