Results 1 to 3 of 3
- 09-28-2010, 05:13 PM #1
Member
- Join Date
- Sep 2010
- Posts
- 1
- Rep Power
- 0
need some help finding average on java
I need to write a program that lists nonnegative #s, then display the smallest and largest integer as well as the average. In my program, I have it so it lists the smallest and largest integer but I don't know how to find the averages of the integers, help would be greatly appreciated. thanks!
Java Code:public class average { public static void main(String[] args) { System.out.println("Enter all integers."); System.out.println("Enter a negative number after"); System.out.println("You have entered all integers"); Scanner keyboard= new Scanner(System.in); double max=keyboard.nextDouble(); double min=max; double next=keyboard.nextDouble(); do { int numberOfintegers=6; double average, sum=0; for (int count =1; count<=numberOfintegers; count++) { next=keyboard.nextDouble(); sum=sum+next; } if (numberOfintegers>=0) average=sum/numberOfintegers; else System.out.println("No integers to average"); } while (next>0); { if (next>max) max=next; else if (next<min) min=next; next=keyboard.nextDouble(); } System.out.println("The highest integer is" + max); System.out.println("The lowest interger is" + min); } }Last edited by Eranga; 09-29-2010 at 04:24 AM. Reason: code tags added
- 09-28-2010, 06:16 PM #2
Get rid of that code for now and take a pencil to write down the algorithm in pseudo code.
Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
The Ubiquitous Newbie Tips
- 09-29-2010, 04:26 AM #3
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
@OP, please use code tags next time posting. If you don't know how to do it, check on my forum signature. You can find a relevant link.
Regarding your question, just forget about Java. How did you calculate average in maths? If you know the logic what you've to do is, convert it into a Java code.
Similar Threads
-
Java RECURSION help..finding the second last member in the List?
By racewithferrari in forum New To JavaReplies: 3Last Post: 04-14-2011, 06:59 AM -
Please help me out in finding Video Tutorials for JAVA
By ravuri3986 in forum New To JavaReplies: 5Last Post: 03-17-2010, 04:26 AM -
help...! about reading a text file and finding their average
By nemesis in forum New To JavaReplies: 20Last Post: 10-20-2008, 11:02 AM -
I need help with my java servlet homework(average)
By jellyfish888 in forum Java ServletReplies: 2Last Post: 12-23-2007, 09:57 PM -
Finding GCF in java
By lenny in forum Advanced JavaReplies: 1Last Post: 07-31-2007, 05:41 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks