Help please Java

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ryann18
    New Member
    • Oct 2006
    • 22

    Help please Java

    I need to also know what happens if two or more values are equal and if exactly two values are equal, does it matter whether the equal values are lower or higher than the third??

    import java.util.Scann er;

    public class MinOfThree

    {
    //-----------------------------------------------------------------
    // Reads three integers from the user and determines the smallest
    // value.
    //-----------------------------------------------------------------
    public static void main (String[] args)
    {
    int num1, num2, num3, min = 0;

    Scanner scan = new Scanner (System.in);

    System.out.prin tln ("Enter three integers: ");
    num1 = scan.nextInt();
    num2 = scan.nextInt();
    num3 = scan.nextInt();

    if (num1 < num2)
    if (num1 < num3)
    min = num1;
    else
    min = num3;
    else
    if (num2 < num3)
    min = num2;
    else
    min = num3;

    System.out.prin tln ("Minimum value: " + min);

    }

    }
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Originally posted by ryann18
    I need to also know what happens if two or more values are equal and if exactly two values are equal, does it matter whether the equal values are lower or higher than the third??

    import java.util.Scann er;

    public class MinOfThree

    {
    //-----------------------------------------------------------------
    // Reads three integers from the user and determines the smallest
    // value.
    //-----------------------------------------------------------------
    public static void main (String[] args)
    {
    int num1, num2, num3, min = 0;

    Scanner scan = new Scanner (System.in);

    System.out.prin tln ("Enter three integers: ");
    num1 = scan.nextInt();
    num2 = scan.nextInt();
    num3 = scan.nextInt();

    if (num1 < num2)
    if (num1 < num3)
    min = num1;
    else
    min = num3;
    else
    if (num2 < num3)
    min = num2;
    else
    min = num3;

    System.out.prin tln ("Minimum value: " + min);

    }

    }
    Why don't you run it with different values? It's the best way to understand these things

    Comment

    Working...