importjava.util.Scanner;publicclassCatAndMouse{publicstaticvoidmain(String[]args){Scannersc=newScanner(System.in);System.out.println("Enter the string x");Stringx=sc.nextLine();System.out.println("Enter the jump");intj=sc.nextInt();x=x.toLowerCase();intposofc=x.indexOf('c')+1,posofm=x.indexOf('m')+1,posofdog=x.indexOf('d');if(posofdog>0){//Check if dog is in betweenintstart=posofc>posofm?posofm:posofc;intend=posofc>posofm?posofc:posofm;if(start<posofdog&&end>posofdog){System.out.println("Protected");System.exit(0);}}intcompare=posofc<posofm?(posofm-posofc-1):(posofc-posofm-1);if(compare>j){System.out.println("Escape");}else{System.out.println("Caught");}}}
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
JAVA