|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Highest/Lowest Int values
Hi,
Can you help with a simple yet puzzling piece of code. I'm new to programming and I'm using the while loop. I'm entering all different ints values plus I'm terminating when I get to '0'. I full understanding how to add up all the int values. However if I enter three different int values how do I display the highest or lowest value alone? Code below: Code:
public class HighNumber {
public static void main(String[] args) {
Int sum = 0;
Int aNumber = -1;
While (aNumber=!0) // is not 0 java code!
aNumber = JFB.getInt("Type a number, please (0 to stop):");
sum = sum + aNumber:}
JFB.display("The highest number is" + sum );
}
}
The code is in java but it can be switched to C++ or vbscript. Any feedback would be greatly appreciated. |
|
#2
|
||||
|
||||
|
--moved to the general Programming forum. what made you post in VB forum??
anyway, to do what you want, you have to work with variables, remembering the highest and lowest value. Code:
Int sum = 0;
Int aNumber = -1;
Int max = -999999;
Int min = 999999;
While (aNumber != 0)
{
aNumber = JFB.getInt("Type a number, please (0 to stop):");
if (aNumber != 0)
{
sum = sum + aNumber;
if (aNumber > max)
max = aNumber;
if (aNumber < min)
min = aNumber;
}
}
JFB.display("The highest number i s" + max );
JFB.display("The lowest number is " + min );
JFB.display("The sum is " + sum );
hope this is clear enough, let me know if not.. |
|
#3
|
|||
|
|||
|
Thanks it worked
cheers Shadow wizard code works! ..... ps you have exquisite taste in ladies my friend. Quote:
|
|
#4
|
||||
|
||||
|
Quote:
![]() feel free to stick around, if you liked that lady there's good chance you would like other things in our Lounge. ![]() |
![]() |
| Viewing: ASP Free Forums > Other > Programming Help > Highest/Lowest Int values |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|