Results 1 to 2 of 2
  1. #1
    jbinx is offline Member
    Join Date
    Oct 2015
    Posts
    2
    Rep Power
    0

    Default Comparing two numbers using if/else statements

    Alright so I'm stumped trying to figure out how to compare two numbers to determine which one is larger and which one is smaller using if/else statements. So as it stands whenever I compile my code I get the error "method setNums in class NumberCompare cannot be given to applied types; required: no arguments, found:int,int; reason:actual and formal argument lists differ in length" I am pretty sure the my class is not done well. So here is what I currently have.

    NumberCompare class:
    Java Code:
    import static java.lang.System.*;
    
    public class NumberCompare
    {
        private int numberA, numberB;
        public NumberCompare(int a, int b)
        {
            numberA=a;
            numberB=b;
        }
        public void setNums ()
        {
            numberA = 45;
            numberB = 45;
        }
        public int getLargest ()
        {
            if(numberA > numberB)
                System.out.println(+numberA+" is greater than " +numberB);
                return numberA;
            }
        public int getSmallest ()
        {
            if(numberA < numberB)
                System.out.println(+numberB+" is less than " +numberA);
                return numberB;
        }
    }
    and the runner class:
    Java Code:
    import static java.lang.System.*;
    public class NumberCompareRunner
    {
        public static void main( String args[] )
            {
                NumberCompare test = new NumberCompare(5,6);
                out.println(test);
                out.println("largest == " + test.getLargest());
                out.println("smallest == " + test.getSmallest()+"\n\n");
                test.setNums(45,45);
                out.println(test);
                out.println("largest == " + test.getLargest());
                out.println("smallest == " + test.getSmallest()+"\n\n");
                test.setNums(-25,10324);
                out.println(test);
                out.println("largest == " + test.getLargest());
                out.println("smallest == " + test.getSmallest()+"\n\n");
            }
    }
    So in short my issue is that I can't get two numbers to be compared against each other. Thanks for any and all help.
    Last edited by JosAH; 10-22-2015 at 06:58 AM. Reason: added [code] ... [/code] tags

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,422
    Blog Entries
    7
    Rep Power
    28

    Default Re: Comparing two numbers using if/else statements

    Your setNums() method is defined without parameters but you're trying to call it as if it took two parameters; the compiler doesn't like that.

    kind regards,

    Jos

    ps. I added code tags to your code for readability reasons.
    Build a wall around Donald Trump; I'll pay for it.

Similar Threads

  1. Replies: 2
    Last Post: 03-02-2013, 03:24 AM
  2. comparing phone numbers
    By paul1024 in forum New To Java
    Replies: 5
    Last Post: 09-19-2011, 12:00 AM
  3. Comparing 3 or more numbers
    By W00tbeer1 in forum New To Java
    Replies: 8
    Last Post: 10-11-2010, 07:03 AM
  4. Printing ranges of numbers using if/else statements
    By russbuss106 in forum New To Java
    Replies: 8
    Last Post: 03-05-2009, 05:03 AM
  5. Problem comparing three numbers
    By gammaman in forum New To Java
    Replies: 1
    Last Post: 02-09-2008, 05:43 PM

Tags for this Thread

Posting Permissions

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