array of booleans

Z

zeus2

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>
 
J

jessu

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
}
 
Z

zeus2

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
 
R

Roedy Green

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.
 
Z

zero

(e-mail address removed) wrote in @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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,983
Messages
2,570,187
Members
46,747
Latest member
jojoBizaroo

Latest Threads

Top