Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Simple one... (Java)

Options
  • 02-02-2006 12:03am
    #1
    Closed Accounts Posts: 521 ✭✭✭


    Simple but i cant figure it out or just plain dont know why....
    In college but havent had to look at java in a while.

    public double blance(String nm){
         for(int j = 0; j < nameID.length; j++){
              if(nm == name[j])
                   return bal[j];          
         }
         return defaultBal;
    }
    

    Now... Why does the default value (defaultBal) get returned?
    I have narrowed the problem down to here... every thing else is working.


Comments

  • Closed Accounts Posts: 17,208 ✭✭✭✭aidan_walsh


    name[j] is a String? In that case you need to compare nm.equals(name[j]), otherwise you are checking to see is it the same Object, not an equivilant String.


  • Closed Accounts Posts: 521 ✭✭✭EOA_Mushy


    Thats exactly it! Thanks dude!

    Forgot ".equals()" existed
    :D


Advertisement