Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > array of booleans

Reply
Thread Tools

array of booleans

 
 
zeus2@hotmail.com
Guest
Posts: n/a
 
      10-01-2005
how do i write code to provide default values, if user enters a single
space(or non-numeric value) when asked to enter a value, and
substituite the lowest numerical value still available. I would like to
use an array of booleans! I would like to assume that the user will
simply hit entre<enter>

 
Reply With Quote
 
 
 
 
jessu
Guest
Posts: n/a
 
      10-01-2005
Its not clear what your question is....

You can find whether the user has entered any values by trimming the
input string and checking its length.

String input = consoleReader.readLine();
input = input.trim();
if( input.length() == 0 ) )
{
//nothing was entered
}

----------------
FeedFeeds : A new way to read news and blogs!
http://www.feedfeeds.com

 
Reply With Quote
 
 
 
 
zeus2@hotmail.com
Guest
Posts: n/a
 
      10-01-2005
perahps this sample output might help. I have an array for the votes,
however, when no NUMERIC vote is entered, i want to be able to default
the lowest number, 1,2 in this case for the votes that have not been
physically entered. Don't i need to store it in an array? Some
pseudocode would be helpful in breaking the problem down..

cheers...peri

Please enter the next vote
Ballot paper 1
Please enter the next vote (for Brad): 3
Please enter the next vote (for Candidate 2): <---no vote(defaults 1)
Please enter the next vote (for Julian): <---no vote(defaults 2)
Please enter the next vote (for Rob): 4
Please enter the next vote (for Ian): 5
(E)nter or (R)eset ballot paper: e
Vote 1 entered; Please enter the next vote
Do you have more ballot papers to enter (Y/N): n


jessu wrote:
> Its not clear what your question is....
>
> You can find whether the user has entered any values by trimming the
> input string and checking its length.
>
> String input = consoleReader.readLine();
> input = input.trim();
> if( input.length() == 0 ) )
> {
> //nothing was entered
> }
>
> ----------------
> FeedFeeds : A new way to read news and blogs!
> http://www.feedfeeds.com


 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      10-01-2005
On 30 Sep 2005 22:23:02 -0700, http://www.velocityreviews.com/forums/(E-Mail Removed) wrote or quoted :

>how do i write code to provide default values, if user enters a single
>space(or non-numeric value) when asked to enter a value, and
>substituite the lowest numerical value still available. I would like to
>use an array of booleans! I would like to assume that the user will
>simply hit entre<enter>


you get the input, trim it and if you have an empty string you set
your value to the default, otherwise you continue as if there were no
default.
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.
 
Reply With Quote
 
zero
Guest
Posts: n/a
 
      10-01-2005
(E-Mail Removed) wrote in news:1128145921.794117.187320
@g49g2000cwa.googlegroups.com:

> perahps this sample output might help. I have an array for the votes,
> however, when no NUMERIC vote is entered, i want to be able to default
> the lowest number, 1,2 in this case for the votes that have not been
> physically entered. Don't i need to store it in an array? Some
> pseudocode would be helpful in breaking the problem down..
>
> cheers...peri
>
> Please enter the next vote
> Ballot paper 1
> Please enter the next vote (for Brad): 3
> Please enter the next vote (for Candidate 2): <---no vote(defaults 1)
> Please enter the next vote (for Julian): <---no vote(defaults 2)
> Please enter the next vote (for Rob): 4
> Please enter the next vote (for Ian): 5
> (E)nter or (R)eset ballot paper: e
> Vote 1 entered; Please enter the next vote
> Do you have more ballot papers to enter (Y/N): n
>
>



I don't think you need an array of booleans here. You just keep track of
what the current lowest number is, and if nothing was entered, you use
this lowest number.


in pseudo code:

initialize lowestInt to 1
read the input
if input is not an integer
{
value = lowestInt
lowestInt++
}
else
value = input
use value


Note that this does not account for the user entering 1 on the first
line, then nothing on the second. In this case you'll have 1 for both
votes.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
initialize an array of booleans bob smith Java 3 08-01-2012 06:09 PM
initialize an array of booleans bob smith Java 3 07-31-2012 09:08 PM
g++: integers as booleans, no warning? Martin Herbert Dietze C++ 9 02-18-2005 09:03 AM
Re: Booleans and comparison results =?ISO-8859-1?Q?Gerhard_H=E4ring?= Python 0 06-24-2003 03:49 PM
Booleans and comparison results Roman Suzi Python 0 06-24-2003 03:19 PM



Advertisments