Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*; public class H231 {public static void main (String[] args) {while (JPL.test()) {
- ////////////////////////////// PROBLEM STATEMENT //////////////////////////////
- // Given a string, print true if the number of appearances of "is" anywhere //
- // in the string is equal to the number of appearances of "not" anywhere in //
- // the string (case sensitive). //
- // "This is not" -> false //
- // "This is notnot" -> true //
- // "noisxxnotyynotxisi" -> true //
- ///////////////////////////////////////////////////////////////////////////////
- // >>>>>> Your Java Code Fragment starts here <<<<<<
- Scanner kb=new Scanner(System.in);
- String toSearch=kb.nextLine();
- int strLength=toSearch.length();
- int isCount=0;
- int notCount=0;
- for (int i=1;i<strLength;i++) {
- if (toSearch.charAt(i)=='s' && toSearch.charAt(i-1)=='i') {
- isCount++;
- }
- if (i>=2) {
- if (toSearch.charAt(i)=='t' && toSearch.charAt(i-1)=='o' && toSearch.charAt(i-2)=='n') {
- notCount++;
- }
- }
- }
- if (isCount == notCount) {
- System.out.print(true);
- } else {
- System.out.print(false);
- }
- // >>>>>> Your Java Code Fragment ends here <<<<<<
- }}}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement