Results 1 to 3 of 3
  1. #1
    jtw0812 is offline Member
    Join Date
    Sep 2010
    Posts
    1
    Rep Power
    0

    Default 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 05:24 AM. Reason: code tags added

  2. #2
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,430
    Rep Power
    7

    Default

    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

  3. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    @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

  1. Replies: 3
    Last Post: 04-14-2011, 07:59 AM
  2. Please help me out in finding Video Tutorials for JAVA
    By ravuri3986 in forum New To Java
    Replies: 5
    Last Post: 03-17-2010, 05:26 AM
  3. Replies: 20
    Last Post: 10-20-2008, 12:02 PM
  4. I need help with my java servlet homework(average)
    By jellyfish888 in forum Java Servlet
    Replies: 2
    Last Post: 12-23-2007, 10:57 PM
  5. Finding GCF in java
    By lenny in forum Advanced Java
    Replies: 1
    Last Post: 07-31-2007, 06:41 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
  •