Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Simple one... (Java)

  • 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