The Artima Developer Community
Sponsored Link

Java Answers Forum
Confused, small boolean problem

2 replies on 1 page. Most recent reply: Apr 9, 2003 7:35 AM by Senthoorkumaran Punniamoorthy

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 2 replies on 1 page
Just

Posts: 6
Nickname: rusty
Registered: Mar, 2003

Confused, small boolean problem Posted: Mar 29, 2003 11:52 PM
Reply to this message Reply
Advertisement
I have never used Boolean in java before, I?m finding it very frustrating, please help!.

Okay this is the problem.
This program is meant to prompt the user to enter either, i, r or e. each letter is support to prompt the user to do something else, by printing on to the screen.

this is the code.

public
{
public static boolean Main (String [ ] args)

boolean i,r,e;
int prompt, promtpt1, prompt2

System.out.println ("enter i,r and or e");

if (i)
System.out.println ("next step")
Keyboard.readint;

if (r)
System.out.println ("next step")
Keyboard.readint;

if (e)
System.out.println ("exit, bye")
Keyboard.readint;

else
System.out.println ("only i,r or e can be used, bye")
Keyboard.readint;

}

}


Rich Burgis

Posts: 17
Nickname: songbird
Registered: Mar, 2003

Re: Confused, small boolean problem Posted: Mar 30, 2003 6:56 PM
Reply to this message Reply
When do you give a value to i, r or e?

You say
System.out.println( "Enter i, r or e" );

When do you read the result?

if you do you will have o assign a value to each boolean as in

char result = System.in.read( );

i = r = e = false;

if( result == 'i' )
i = true;
else if( result == 'r' )
r = true;
else if(result == 'e' )
e = true;

Then your conditionals will work

Senthoorkumaran Punniamoorthy

Posts: 335
Nickname: senthoor
Registered: Mar, 2002

Re: Confused, small boolean problem Posted: Apr 9, 2003 7:35 AM
Reply to this message Reply
Or a better option would be to not using Boolean and just to use "char" type. Store the input into the char variable and then use "case" statement to do your conditional work?

Flat View: This topic has 2 replies on 1 page
Topic: need help with some simple code. Previous Topic   Next Topic Topic: Java Applets on linux

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use