Results 1 to 3 of 3

Thread: Boolean help

  1. #1
    FadedAura is offline Member
    Join Date
    Nov 2011
    Posts
    26
    Rep Power
    0

    Default Boolean help

    Sorry for asking to many questions. Am needing to implement boolean logic (or so i think) and was wondering how i go about doing this.

    Java Code:
    public class InnerInsulation {
        
        boolean yes, no;
        
        public InnerInsulation()
        {
            yes = true;
            no = false;
            
            Scanner in = new Scanner(System.in);
            
            CheckColour cl = new CheckColour();
            
            if (cl.getUserColour() == 0 || cl.getUserColour() == 1)
            {
                System.out.println("Inner insulation is not available for the number of colour(s) choosen");
            }
            else if (cl.getUserColour() == 2)
            {
                System.out.println("Would you like insulation?");
            }
        }   
    }
    The boolean is for the else if statement. I need a system.in but no sure how to implement boolean.

    All help will be appreciated.

  2. #2
    Iron Lion is offline Senior Member
    Join Date
    Nov 2010
    Posts
    210
    Rep Power
    4

    Default Re: Boolean help

    Do you mean you want to get input from the user, and set a boolean variable to true for yes and false for no?

    If so, the variables yes and no are unnecessary. Try something like this:

    Java Code:
    String input = in.nextLine();
    boolean wantsInsulation = (input.equalsIgnoreCase("Y") || input.equalsIgnoreCase("YES");
    Does that make sense?

  3. #3
    FadedAura is offline Member
    Join Date
    Nov 2011
    Posts
    26
    Rep Power
    0

Similar Threads

  1. Replies: 3
    Last Post: 09-13-2011, 01:01 AM
  2. boolean error help when no boolean is given
    By drewtrcy in forum New To Java
    Replies: 18
    Last Post: 05-05-2011, 10:04 AM
  3. boolean even or odd?
    By shazakala in forum New To Java
    Replies: 3
    Last Post: 04-17-2011, 09:02 AM
  4. Boolean help
    By DMarsh12 in forum New To Java
    Replies: 8
    Last Post: 04-11-2011, 10:41 PM
  5. use boolean as 0 or 1
    By joost_m in forum New To Java
    Replies: 10
    Last Post: 04-13-2010, 12:22 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •