Results 21 to 27 of 27
 11142011, 12:41 AM #21Member
 Join Date
 Nov 2011
 Posts
 19
 Rep Power
 0
Re: smallest number and largest number using while and if statements
ok so i tryed doing it and i thought it would work but it didnt. this program is due tomorrow so i am getting angry too becuase i have tried alot of things .
my new code is:
package whilesmalllarge;
import TerminalIO.KeyboardReader;
public class Smalllarge {
public static void main(String[] args) {
KeyboardReader reader = new KeyboardReader();
double usernumber = 0 ;
double i = 0 ;
double count;
double highest = 0;
double smallest = 0;
boolean noNumbersYet;
count =reader.readInt(" How long is the list?");
while( i < count){
usernumber = reader.readInt(" input a number:");
i++;
}
noNumbersYet = true;
if (noNumbersYet){
smallest= usernumber;
}else if (usernumber < smallest){
smallest= usernumber;
noNumbersYet= false;
}
System.out.print("The smallest number is :"+ smallest);
}
}
do i just have to add something else after it? if so what?
 11142011, 08:13 AM #22AlphaSupport Guest
Re: smallest number and largest number using while and if statements
First of all, when posting code to the forums, please surround it with [code]...[/code]. That way your post will be more readable.
The "noNumbersYet= false;" is at the wrong place, it will never get executed. ;)
 11142011, 08:41 AM #23
 Join Date
 Sep 2008
 Location
 Voorschoten, the Netherlands
 Posts
 14,321
 Blog Entries
 7
 Rep Power
 25
Re: smallest number and largest number using while and if statements
The only person who got everything done by Friday was Robinson Crusoe.
 11142011, 08:50 AM #24AlphaSupport Guest
Re: smallest number and largest number using while and if statements
Lol correct, didn't even look that further. But there are more things wrong in the current version. ;)
(And i don't even speak Java)
Edit:
Actually it looks like the whole
Java Code:noNumbersYet = true; if (noNumbersYet){ smallest= usernumber; }else if (usernumber < smallest){ smallest= usernumber; noNumbersYet= false;
 11142011, 09:04 AM #25
 Join Date
 Sep 2008
 Location
 Voorschoten, the Netherlands
 Posts
 14,321
 Blog Entries
 7
 Rep Power
 25
Re: smallest number and largest number using while and if statements
The only person who got everything done by Friday was Robinson Crusoe.
 11142011, 03:17 PM #26Member
 Join Date
 Nov 2011
 Posts
 19
 Rep Power
 0
Re: smallest number and largest number using while and if statements
Ok I will be honest yes I guess I did basically copy your code. I did think about how it works and yes it made sense to me. However the Boolean thing is quite new to me. I remember that my teacher talked maybe a little about it but we never used it in our code so I didn’t really understand that part. My code now luckily works. I basically played around with it and I finally got it into the right order. But can someone please explain to me how the Boolean works. Like what happens when you set it to true and when you set it to false. I just want to know for future programs that I will do. You can close this threat after that.
 11142011, 03:22 PM #27
 Join Date
 Sep 2008
 Location
 Voorschoten, the Netherlands
 Posts
 14,321
 Blog Entries
 7
 Rep Power
 25
Re: smallest number and largest number using while and if statements
A boolean variable can take one of two values: true or false; their value can be used in iftests, just like any other boolean value; nothing special happens when you set the value of a boolean variable, nothing explodes nor do penguins pop up on top of your television set, nothing.
kind regards,
JosThe only person who got everything done by Friday was Robinson Crusoe.
Similar Threads

Find the Biggest Number + Smallest
By d4v1dz in forum New To JavaReplies: 19Last Post: 10262011, 06:43 AM 
How can I find out the largest number ... ?
By TheTypicalStudent in forum New To JavaReplies: 14Last Post: 05032011, 11:09 AM 
Find the second largest number in the array
By radhi16 in forum New To JavaReplies: 5Last Post: 01132011, 06:08 PM 
smallest number java program
By elmo in forum New To JavaReplies: 9Last Post: 11182010, 10:29 PM 
Finding the largest number in an array
By starchildren3317 in forum New To JavaReplies: 14Last Post: 11032010, 07:49 AM
Bookmarks