Results 1 to 3 of 3
  1. #1
    mazzer07 is offline Member
    Join Date
    Oct 2013
    Posts
    3
    Rep Power
    0

    Default Java Program: Get the biggest number out of a list ? Help ??

    Hello guys,

    I am pretty new to java and I have an assignment that I need to do. The aim of the program is to find the maximum of a given list of numbers. The program should tell the number together with its index in the list ( counting from zero). If two of the are equal than It should print als othe lowest index.

    This is what I got until now. Please, can someone help me out to finish it.


    Java Code:
    public class Numbers
    {
     public static void main(String[] args)
     {
      double Number = Double.parseDouble(args[0]);
      double maxSoFar = Number;
      for (int restNumbers = 1; restNumbers < args.length; restNumbers++)
       {
       int InputNumbers = Integer.parseInt(args[restNumbers]);
       if (InputNumbers < maxSoFar)
       {
       System.out.println("The maximum number is" + maxSoFar);
       maxSoFar = maxSoFar;
       }
        else if (InputNumbers > maxSoFar)
        {
         System.out.println("The bigest number is" + InputNumbers);
         maxSoFar ++;
         }
        else if (InputNumbers == maxSoFar)
        {
         System.out.println("The biggests numbers are" + InputNumbers +" and "
                          + maxSoFar + " in positions " + restNumbers);
         maxSoFar ++;
        }  
       } // for
    
     }
    }

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,424
    Rep Power
    5

    Default Re: Java Program: Get the biggest number out of a list ? Help ??

    You haven't told us what the problem is. How is your program not working?

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  3. #3
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,762
    Rep Power
    7

    Default Re: Java Program: Get the biggest number out of a list ? Help ??

    Java Code:
    maxSoFar = maxSoFar;
    Surely you can see that line of code is totally pointless.
    Java Code:
     maxSoFar ++;
    Huh?

    If maxSoFar is 10 and the next number is 31 which is greater than 10 you increment maxSoFar to 11. I repeat Huh?
    Last edited by Junky; 10-28-2013 at 01:42 AM.

Similar Threads

  1. Replies: 11
    Last Post: 06-23-2013, 04:43 PM
  2. Replies: 0
    Last Post: 10-10-2012, 10:27 PM
  3. Find the Biggest Number + Smallest
    By d4v1dz in forum New To Java
    Replies: 19
    Last Post: 10-26-2011, 06:43 AM
  4. smallest number java program
    By elmo in forum New To Java
    Replies: 9
    Last Post: 11-18-2010, 09:29 PM
  5. Replies: 1
    Last Post: 07-02-2008, 01:58 PM

Posting Permissions

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