Results 1 to 10 of 10
 11012012, 05:02 PM #1Member
 Join Date
 Nov 2012
 Posts
 4
 Rep Power
 0
finding maximum,minimum and average of 10 numbers
hello,i am a complete beginner to java programming.what's wrong with this program is how do i find the minimum of the given numbers.what value do i need to assign to the min variable?any help would be appriciated.
Java Code:import java.util.Scanner; public class onem { public static void main (String[]args) { Scanner k=new Scanner(System.in); int sum=0; int i=1; int min=0; int max=0; int avg=0; while(i<=10) { int n; System.out.println("write a number"); n=k.nextInt(); if (n<min) { n=min; } else{} if (n>max) { max=n; } sum=sum+n; i++; } avg=sum/10; System.out.println(min); System.out.println(avg); System.out.println(max); } }
 11012012, 05:52 PM #2
Re: finding maximum,minimum and average of 10 numbers
There are a ton of ways to handle this case. I bet if you think about it a little harder you'll get it. What have you tried?
How to Ask Questions the Smart Way
Static Void Games  GameDev tutorials, free Java and JavaScript hosting!
Static Void Games forum  Come say hello!
 11012012, 05:56 PM #3Moderator
 Join Date
 Apr 2009
 Posts
 13,541
 Rep Power
 27
Re: finding maximum,minimum and average of 10 numbers
Java Code:if (n<min) { n=min; }
Please do not ask for code as refusal often offends.
** This space for rent **
 11012012, 06:13 PM #4Member
 Join Date
 Nov 2012
 Posts
 4
 Rep Power
 0
Re: finding maximum,minimum and average of 10 numbers
i have tried
Java Code:if (n<min) //here's the problem{ n=min; }
 11012012, 06:29 PM #5Moderator
 Join Date
 Apr 2009
 Posts
 13,541
 Rep Power
 27
Re: finding maximum,minimum and average of 10 numbers
No.
You want to change the 'min' value if 'n' is smaller.
At the moment you are changing the 'n' value.Please do not ask for code as refusal often offends.
** This space for rent **
 11012012, 06:36 PM #6
 Join Date
 Sep 2008
 Location
 Voorschoten, the Netherlands
 Posts
 14,422
 Blog Entries
 7
 Rep Power
 28
Re: finding maximum,minimum and average of 10 numbers
Assignments work 'from right to left', i.e. a= b means that a gets the value of b; so in your example it should be;
Java Code:if (n < min) min= n;
JosBuild a wall around Donald Trump; I'll pay for it.
 11012012, 11:16 PM #7
 11022012, 09:44 AM #8Member
 Join Date
 Nov 2012
 Posts
 4
 Rep Power
 0
Re: finding maximum,minimum and average of 10 numbers
Java Code:int min=0;
Today, 04:16 AMJunky
Re: finding maximum,minimum and average of 10 numbers
Originally Posted by xxbakugan
Java Code:
1
else{}
 11022012, 10:03 AM #9Moderator
 Join Date
 Apr 2009
 Posts
 13,541
 Rep Power
 27
Re: finding maximum,minimum and average of 10 numbers
Also (and I have to admit to only thinking of this last night)...
Java Code:int min = 0;
You should assign a really big number to 'min', and a really big negative number to 'max' (the Integer class has a couple of constants).Please do not ask for code as refusal often offends.
** This space for rent **
 11022012, 10:13 AM #10Member
 Join Date
 Nov 2012
 Posts
 4
 Rep Power
 0
Similar Threads

Maximum or Minimum cell value in a column (JTable)
By gilmap in forum New To JavaReplies: 2Last Post: 07272011, 07:35 PM 
Finding minimum and maximum of 'n' numbers...please help!
By snw19 in forum New To JavaReplies: 8Last Post: 03252011, 11:38 PM 
Maximum Minimum Values
By z6StringAssasin in forum New To JavaReplies: 2Last Post: 05092010, 12:36 AM 
Calculating Maximum and Minimum
By Ejava in forum New To JavaReplies: 6Last Post: 03012010, 04:36 PM 
To find the Maximum and Minimum in an Array of Strings
By luscious in forum JavaServer Pages (JSP) and JSTLReplies: 9Last Post: 07312008, 01:51 PM
Bookmarks