Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #39299
| X-Received | by 2002:ae9:e841:: with SMTP id a62mr11846672qkg.384.1581951451291; Mon, 17 Feb 2020 06:57:31 -0800 (PST) |
|---|---|
| X-Received | by 2002:a25:870b:: with SMTP id a11mr15602257ybl.330.1581951451075; Mon, 17 Feb 2020 06:57:31 -0800 (PST) |
| Path | csiph.com!xmission!news.snarked.org!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail |
| Newsgroups | comp.lang.java.programmer |
| Date | Mon, 17 Feb 2020 06:57:30 -0800 (PST) |
| Complaints-To | groups-abuse@google.com |
| Injection-Info | google-groups.googlegroups.com; posting-host=96.86.183.2; posting-account=kTs1ygoAAACgG1TSoyECpovEyy-V6_8b |
| NNTP-Posting-Host | 96.86.183.2 |
| User-Agent | G2/1.0 |
| MIME-Version | 1.0 |
| Message-ID | <2542dd61-cde8-4a30-89be-2abfca122ac9@googlegroups.com> (permalink) |
| Subject | Writing Java code while high and drunk |
| From | chad altenburg <cdalten@gmail.com> |
| Injection-Date | Mon, 17 Feb 2020 14:57:31 +0000 |
| Content-Type | text/plain; charset="UTF-8" |
| Content-Transfer-Encoding | quoted-printable |
| Lines | 44 |
| Xref | csiph.com comp.lang.java.programmer:39299 |
Show key headers only | 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 | Next — Next in thread | Find similar | Unroll 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