java programming

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • monkey1001
    New Member
    • Dec 2007
    • 10

    #1

    java programming

    hi, am stuck on writting a java program that will output three integers in descending order(highest to lowest)...pleas e helppp...thks.. this is what i got and i think tht its so wrong..

    public class HighToLow
    {
    public static void main(int a, int b, int c)
    {
    int max = a;
    int med = b;
    int low = c;
    int temp;

    if(a < b)
    {
    temp = a;
    a = b;
    b = temp;
    }
    }
    }
  • heat84
    New Member
    • Nov 2007
    • 118

    #2
    Originally posted by monkey1001
    hi, am stuck on writting a java program that will output three integers in descending order(highest to lowest)...pleas e helppp...thks.. this is what i got and i think tht its so wrong..

    public class HighToLow
    {
    public static void main(int a, int b, int c)
    {
    int max = a;
    int med = b;
    int low = c;
    int temp;

    if(a < b)
    {
    temp = a;
    a = b;
    b = temp;
    }
    }
    }
    Can you read a little bit about sorting and decide on the sorting algorithm that suits you . You are on the right track on assigning the variables to a temporary variable.

    Comment

    • ramadeviirrigireddy
      New Member
      • Jul 2007
      • 54

      #3
      Originally posted by monkey1001
      hi, am stuck on writting a java program that will output three integers in descending order(highest to lowest)...pleas e helppp...thks.. this is what i got and i think tht its so wrong..

      public class HighToLow
      {
      public static void main(int a, int b, int c)
      {
      int max = a;
      int med = b;
      int low = c;
      int temp;

      if(a < b)
      {
      temp = a;
      a = b;
      b = temp;
      }
      }
      }
      Hi,

      If you have only three numbers then you have to compare each number with the other two if u want to display every number( i mean to say high, med and low).

      If i'm wrong then others please correct me.

      Comment

      • JosAH
        Recognized Expert MVP
        • Mar 2007
        • 11453

        #4
        What's wrong with Math.max() and Math.min()?

        kind regards,

        Jos

        Comment

        • heat84
          New Member
          • Nov 2007
          • 118

          #5
          Originally posted by JosAH
          What's wrong with Math.max() and Math.min()?

          kind regards,

          Jos
          Great , that simplifies it.

          Comment

          Working...