Results 1 to 3 of 3
- 01-26-2015, 10:57 PM #1
Member
- Join Date
- Jan 2015
- Posts
- 1
- Rep Power
- 0
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);
}
}
- 01-26-2015, 11:06 PM #2
Senior Member
- Join Date
- Jan 2013
- Location
- Northern Virginia, United States
- Posts
- 6,226
- Rep Power
- 15
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,
JimThe JavaTM Tutorials | SSCCE | Java Naming Conventions
Poor planning on your part does not constitute an emergency on my part
- 01-26-2015, 11:13 PM #3
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,716
- Rep Power
- 19
Similar Threads
-
Method takes array of ints and an integer. Then returns boolean if num is found?
By Denis2k11 in forum New To JavaReplies: 2Last Post: 01-31-2013, 07:37 PM -
Write a Java program that reads integers finds the largest and counts its occurrence.
By bobbyj7 in forum New To JavaReplies: 2Last Post: 10-06-2012, 05:29 AM -
Help. Create 2D array method that returns index of row that contains the most zeros.
By jlss4e in forum New To JavaReplies: 3Last Post: 08-21-2011, 03:25 AM -
My capture sound method returns empty byte array tho I have mic plugged in?
By Addez in forum New To JavaReplies: 2Last Post: 06-05-2011, 12:52 AM -
How do I write a method that returns an array where ith element contains a[i] + b[i]?
By CaptainBlood in forum New To JavaReplies: 5Last Post: 10-30-2010, 01:05 AM
Bookmarks