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
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Simple one... (Java)

  • 01-02-2006 11:03pm
    #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