Results 1 to 3 of 3
  1. #1
    RCS
    RCS is offline Member
    Join Date
    Jan 2015
    Posts
    1
    Rep Power
    0

    Default Write a Java method that returns the largest value of an array of doubles?

    Write a Java method that returns the largest value of an array of doubles passed to the method as an argument.
    Back into java wasn't sure how to do it for doubles did one in the main for integers and then added a method changed from int to double and now i'm lost as go why its not working.



    package kickstarter9;

    public class Kickstarter9 {
    public static void main(String[] args){
    double myList;
    double[] myList = {6.0, 4.1, 2.4, 6.8, 1.9, 9.4, 2.8, 4.6, 9.3};
    // find the largest value in the list

    // assume the largest value is the first value
    public static double myList(){
    double largest = myList[0];

    for (int c = 1; c < myList.length; c++){
    {
    largest = myList[c];
    }
    }
    }
    System.out.println("Largest value: " + largest);
    }
    }

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    14

    Default Re: Write a Java method that returns the largest value of an array of doubles?

    All you are doing is reassigning values to "largest." You need some condition test. And please wrap your code in [code][/code] tags.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  3. #3
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,716
    Rep Power
    18

    Default Re: Write a Java method that returns the largest value of an array of doubles?

    Does that code compile? If not, post the compiler's messages if you don't understand them.

Similar Threads

  1. Replies: 2
    Last Post: 01-31-2013, 06:37 PM
  2. Replies: 2
    Last Post: 10-06-2012, 04:29 AM
  3. Replies: 3
    Last Post: 08-21-2011, 02:25 AM
  4. Replies: 2
    Last Post: 06-04-2011, 11:52 PM
  5. Replies: 5
    Last Post: 10-30-2010, 12:05 AM

Posting Permissions

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