Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #39299

Writing Java code while high and drunk

Newsgroups comp.lang.java.programmer
Date 2020-02-17 06:57 -0800
Message-ID <2542dd61-cde8-4a30-89be-2abfca122ac9@googlegroups.com> (permalink)
Subject Writing Java code while high and drunk
From chad altenburg <cdalten@gmail.com>

Show all headers | View raw


I *attempted* the following problem on codingbat.com while both high and drunk...

"
Given a string, return 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).

equalIsNot("This is not") → false
equalIsNot("This is notnot") → true
equalIsNot("noisxxnotyynotxisi") → true
"

Here is what I came up with...

public boolean equalIsNot(String str) {
  int numberIs = 0;
  int numberNot = 0;
  
  for (int i = 0 ; i <= str.length() - 2; i++) {
    if (str.substring(i, i+2).equals("is") ) {
      numberIs++;
    } 
  }
  

   for (int i = 0 ; i <= str.length() - 3; i++) {
    if (str.substring(i, i+3).equals("not") ) {
      numberNot++;
    }
   }
  
  if (numberIs == numberNot) return true;
  else return false;
}


And here is what I found via Google...

https://github.com/mirandaio/codingbat/blob/master/java/string-3/equalIsNot.java


I don't know which one is more correct. With that, I going to back to listening to my neighbor's having loud sex.

Back to comp.lang.java.programmer | Previous | NextNext in thread | Find similar | Unroll thread


Thread

Writing Java code while high and drunk chad altenburg <cdalten@gmail.com> - 2020-02-17 06:57 -0800
  Re: Writing Java code while high and drunk Arne Vajhøj <arne@vajhoej.dk> - 2020-02-17 12:58 -0500
  Re: Writing Java code while high and drunk Joerg Meier <joergmmeier@arcor.de> - 2020-02-17 22:48 +0100

csiph-web