array of booleans

Discussion in 'Java' started by zeus2@hotmail.com, Oct 1, 2005.

  1. Guest

    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>
     
    , Oct 1, 2005
    #1
    1. Advertising

  2. jessu Guest

    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
     
    jessu, Oct 1, 2005
    #2
    1. Advertising

  3. Guest

    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
     
    , Oct 1, 2005
    #3
  4. Roedy Green Guest

    On 30 Sep 2005 22:23:02 -0700, 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.
     
    Roedy Green, Oct 1, 2005
    #4
  5. zero Guest

    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.
     
    zero, Oct 1, 2005
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Martin Herbert Dietze

    g++: integers as booleans, no warning?

    Martin Herbert Dietze, Feb 17, 2005, in forum: C++
    Replies:
    9
    Views:
    481
    Karl Heinz Buchegger
    Feb 18, 2005
  2. Roman Suzi

    Booleans and comparison results

    Roman Suzi, Jun 24, 2003, in forum: Python
    Replies:
    0
    Views:
    714
    Roman Suzi
    Jun 24, 2003
  3. =?ISO-8859-1?Q?Gerhard_H=E4ring?=

    Re: Booleans and comparison results

    =?ISO-8859-1?Q?Gerhard_H=E4ring?=, Jun 24, 2003, in forum: Python
    Replies:
    0
    Views:
    703
    =?ISO-8859-1?Q?Gerhard_H=E4ring?=
    Jun 24, 2003
  4. bob smith

    initialize an array of booleans

    bob smith, Jul 31, 2012, in forum: Java
    Replies:
    3
    Views:
    187
    Roedy Green
    Jul 31, 2012
  5. bob smith

    initialize an array of booleans

    bob smith, Aug 1, 2012, in forum: Java
    Replies:
    3
    Views:
    191
    Roedy Green
    Aug 1, 2012
Loading...

Share This Page