Go Back   CodingForums.com > :: Server side development > Java and JSP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-26-2008, 07:29 PM   PM User | #1
karla00
New to the CF scene

 
Join Date: Oct 2008
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
karla00 is an unknown quantity at this point
[Resolved] Simple javacode

Im a beginner at java and I've been assigned this exercise I've been working on it for a while now but I just cant seem to get it right.
Return true if the string "cat" and "dog" appear the same number of times in the given string.
this is my code so far.
public boolean catDog(String str)
{
int count = 0;
for (int i=0; i<str.length(); i++)
{
String sub = str.substring(i, i+1);
if (sub.equals("cat"))
count++;
if (sub.equals("dog"))
count--;
}

{return false;}

}

any hints on how to fix it?

http://www.javabat.com/prob?id=String2.catDog

Last edited by karla00; 10-26-2008 at 09:22 PM..
karla00 is offline   Reply With Quote
Old 10-27-2008, 12:46 AM   PM User | #2
karla00
New to the CF scene

 
Join Date: Oct 2008
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
karla00 is an unknown quantity at this point
Never mind all I had to do was assigned different counter variables lol thanks for your hep guys!!
karla00 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:38 PM.


Advertisement
Log in to turn off these ads.