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.


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Checking if an int is the lowest out of 4? (Small issue)

  1. #1
    Junior Member
    Join Date
    Feb 2014
    My Mood
    Thanked 0 Times in 0 Posts

    Default Checking if an int is the lowest out of 4? (Small issue)

    I'm trying to find the int with the lowest value, and I only know how to set it up like this:

    Let's say x1 is the lowest.

    int x1, x2, x3, x4;
    if (x1 < x2 && x1 < x3 && x1 < x4) System.put.println("x1 is the lowest value out of those 4");

    Is there a way to shorten this at all? (It's alright if there isn't, just looking for shortcuts)

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Eastern Florida
    Thanked 2,329 Times in 2,285 Posts

    Default Re: Checking if an int is the lowest out of 4? (Small issue)

    Given 4 variables, it will take some if statements to find the variable with the lowest value.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Super Moderator
    Join Date
    Jun 2013
    So. Maryland, USA
    My Mood
    Thanked 688 Times in 675 Posts

    Default Re: Checking if an int is the lowest out of 4? (Small issue)

    I'm not sure it's worth the effort for just 4 variables, but the problem can be generalized to an efficient solution for any number of variables. That solution would include the use of an array or other collection that would be iterated to find the least value in the collection.

Similar Threads

  1. Sorting from lowest to highest issue
    By cb0688 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: February 24th, 2014, 07:34 AM
  2. List methods add(int k, Data data), set(int k, Data data), remove(int k)
    By Enirox in forum Object Oriented Programming
    Replies: 3
    Last Post: September 20th, 2012, 07:43 AM
  3. scanner and int issue
    By saintnicks in forum What's Wrong With My Code?
    Replies: 3
    Last Post: August 24th, 2012, 02:01 AM
  4. [SOLVED] flightpaths, finding lowest cost -- lowest amount of crossovers
    By CjStaal in forum Algorithms & Recursion
    Replies: 4
    Last Post: May 8th, 2012, 01:47 AM
  5. Replies: 2
    Last Post: February 4th, 2009, 12:24 PM

Tags for this Thread