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 2 of 2

Thread: My if statement seems to be getting skipped over

  1. #1
    Junior Member
    Join Date
    Oct 2012
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default My if statement seems to be getting skipped over

     
    public class SimpsonsParadox{
     
     
      public static boolean isSimpsonExample(int p1y1S, int p1y1T, int p2y1S, int p2y1T, int p1y2S, int p1y2T, int p2y2S, int p2y2T){
     
     
      if (((p1y1S + p1y2S)/(p1y1T + p1y2T) > ((p2y1S + p2y2S)/(p2y1T + p2y2T))) && ((p1y1S/p1y1T) < (p2y1S/p2y1T)) && ((p1y2S/p1y2T) < (p2y2S/p2y2T)))){
      return true;
      } else if ((((p1y1S + p1y2S)/(p1y1T + p1y2T) < ((p2y1S + p2y2S)/(p2y1T+p2y2T)))) && ((p1y1S/p1y1T) > (p2y1S/p2y1T)) && ((p1y2S/p1y2T) > (p2y2S/p2y2T))){
      return true;
      } else
        return false;
     
    }
    }
     
     
    public static void main(String[] args)
    {
    }


    when i run this code with a test code it seems to automatically skip both my if statements and go straight to my else and return false. I tested this also by simply making one if statement be if (p1y1S>1) return true and this is the case for several different tests within my test code so i can't figure out why it is skipping my if statements. any help appreciated
    thanks


  2. #2
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: My if statement seems to be getting skipped over

    So do a sysout on every parameter being passed in and see what does not have the value you expected.
    If that does not work, break up that multiple boolean conditional into multiple conditionals and see the value on an individual basis so you can see what is not working the way you expected. If the body gets skipped, then something evaluated to false somewhere and you have to find it. There are only 3 choices in the first conditional

Similar Threads

  1. Need help with if statement.
    By dreamer in forum Loops & Control Statements
    Replies: 2
    Last Post: May 30th, 2012, 02:27 PM
  2. not a statement?
    By frozen java in forum What's Wrong With My Code?
    Replies: 4
    Last Post: October 23rd, 2011, 08:57 PM
  3. My 'if statements' are skipped after user input
    By Cozilz in forum What's Wrong With My Code?
    Replies: 6
    Last Post: October 8th, 2011, 09:17 PM
  4. If-Else Statement help
    By SnowCrashed in forum Loops & Control Statements
    Replies: 5
    Last Post: February 9th, 2010, 07:57 PM
  5. Weird issue with while loop ending/being skipped
    By ang3c0 in forum Loops & Control Statements
    Replies: 4
    Last Post: December 25th, 2009, 12:09 PM

Tags for this Thread