Results 1 to 3 of 3
  1. #1
    senca is offline Member
    Join Date
    Feb 2010
    Posts
    36
    Rep Power
    0

    Default small method isn't supposed to go under 0

    hey everyone,
    I have created a method like this:

    aantalPas is a variable type int, initialized at 0.
    The problem is that it keeps returning true even when it is 0 and you try to execute the method.


    public boolean stapUit(){
    boolean gelukt=false;
    if(aantalPas>0)
    aantalPas--;
    gelukt=true;
    return gelukt;}

  2. #2
    senca is offline Member
    Join Date
    Feb 2010
    Posts
    36
    Rep Power
    0

    Default

    stupid mistake from my side: brackets!

    public boolean stapUit(){
    boolean gelukt=false;
    if(aantalPas>0.0){
    aantalPas--;
    gelukt=true;}
    return gelukt;}

  3. #3
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,305
    Rep Power
    25

    Default

    returning true even when it is 0
    How/where does your code test if it is 0? besides in the method shown.
    Is there a problem between using double and int? Why test against 0.0 vs 0 if its an int?
    Add a println() to show the value of aantalPas to show if it is > 0.0.

Similar Threads

  1. Values change when they're not supposed to
    By m00nchile in forum New To Java
    Replies: 7
    Last Post: 05-15-2010, 04:16 PM
  2. Replies: 1
    Last Post: 04-23-2010, 05:56 PM
  3. JButton doesn't disappear when it is supposed to?
    By ecliptical in forum New To Java
    Replies: 4
    Last Post: 01-25-2010, 12:41 AM
  4. Help interpreting what a class is supposed to do
    By bornwithnoname in forum New To Java
    Replies: 2
    Last Post: 11-20-2008, 12:19 AM
  5. Small problem
    By ayoood in forum New To Java
    Replies: 2
    Last Post: 06-06-2008, 12:27 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •