Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: Need help with boolean method! =(

  1. #1
    Junior Member
    Join Date
    Dec 2010
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Need help with boolean method! =(

    Ok so here's my code. It has to check if all the array word members of "this" and "wca" array are same.
    If theyre the same i need true.. But if only one of them is wrong it has to give false.

    I know this code is wrong, i use the wordEqual = true or false lines at wrong places. I can't seem to solve it

    If one of the members is wrong, i think it will go to the next member and get the boolean as true again.
    I thought maybe i could break the loop if its an "else", but im not sure if this is completely right. Help please?

    private boolean wordsEqual (WordCountArray wca){
    boolean wordsEqual = false;
    for (int i = 0; i < wca.size(); i++) {
    if (this.getWord(i).equals(wca.getWord(i))) {
    if (this.getIndex(getWord(i)) == (wca.getIndex(getWord(i)))) {
    wordsEqual = true;;

    }
    else {
    break;
    }
    }
    else {
    break;
    }
    wordsEqual = true;
    }
    wordsEqual = false;
    return wordsEqual;


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,181
    My Mood
    Hungover
    Thanks
    141
    Thanked 602 Times in 517 Posts

    Default Re: Need help with boolean method! =(

    So you want to return false if just one of them are not equal, right?

    Hint: That was a hint.

  3. The Following User Says Thank You to KevinWorkman For This Useful Post:

    leao (December 14th, 2010)

  4. #3
    Junior Member
    Join Date
    Dec 2010
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Need help with boolean method! =(

    yes, i still cant figure it out, im a beginner =/

    The Index and Word values of two arrays have to be same.

    Otherwise it has to be false,

    is this code true ? or is there a cleaner version maybe ?

  5. #4
    Junior Member
    Join Date
    Dec 2010
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Need help with boolean method! =(

    Ooooh right ... ok i changed the both "break"s to "return false;"

    thats true right ? =)

  6. #5
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,181
    My Mood
    Hungover
    Thanks
    141
    Thanked 602 Times in 517 Posts

    Default Re: Need help with boolean method! =(

    I don't know, does it work? Does it do what you'd expect?

    If you post your updated code, I can maybe give you some other pointers. Don't forget the code tags though.

Similar Threads

  1. Boolean method returning a boolean value
    By Deprogrammer in forum What's Wrong With My Code?
    Replies: 1
    Last Post: November 21st, 2010, 09:56 AM
  2. Method returning boolean
    By Plural in forum What's Wrong With My Code?
    Replies: 3
    Last Post: November 13th, 2010, 05:45 PM
  3. Some help with boolean
    By JPetroSS in forum Java Theory & Questions
    Replies: 3
    Last Post: November 2nd, 2010, 05:38 AM
  4. [SOLVED] Modification of Boolean function in Java program
    By lotus in forum Java SE APIs
    Replies: 4
    Last Post: July 10th, 2009, 10:15 AM
  5. [SOLVED] Java exception "result already defined"
    By rptech in forum Object Oriented Programming
    Replies: 3
    Last Post: May 20th, 2009, 05:48 AM