aspose file tools*
The moose likes Beginning Java and the fly likes Another newbie question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Another newbie question" Watch "Another newbie question" New topic
Author

Another newbie question

Lenny Leon
Greenhorn

Joined: Feb 21, 2005
Posts: 3
I'm just starting out learning Java and need a little help. I'm supposed to take this truth table and alter it so it displays 1's and 0's instead of true false. I'm assumed to do this I would just need to change the variable type and replace true and false with 1 and 0 but every way I try this does not work. I would just like for someone to point me in the right direction. I would like an explanation so I could understand instead of just an awnser. Thanks in advance



Liam Tiarnach
Ranch Hand

Joined: Aug 06, 2004
Posts: 51
Originally posted by Lenny Leon:
I'm just starting out learning Java and need a little help. I'm supposed to take this truth table and alter it so it displays 1's and 0's instead of true false. I'm assumed to do this I would just need to change the variable type and replace true and false with 1 and 0 but every way I try this does not work. I would just like for someone to point me in the right direction. I would like an explanation so I could understand instead of just an awnser. Thanks in advance


okay, so break down what !p means...
! = a boolean operator that inverts the value of a boolean...
So...

if p is true then !p ( NOT p ) is false, otherwise...
if p is false then !P ( NOT p ) is true... Hmmm... the opposite...

so if you use integers... then you could look at it like this...

if p is 1 then !p ( NOT p) then p is 0, else
if p is 0 then !p ( NOT p) then p is ???
... you can take it from here...

now you got some of the logic, making it work should be easier...


- Liam...<br />- ' He who never sleeps... '
Lenny Leon
Greenhorn

Joined: Feb 21, 2005
Posts: 3
I've got it to work (though I don't think its correct) but in order for it to work I removed the ! operator. It won't compile when I leave it in. How do I fix this so it includes the ! operator?

This is the code with the NOT operator still in. It would not compile this way

Nigel Browne
Ranch Hand

Joined: May 15, 2001
Posts: 673
I didn't want to do all your work for you but look at the code below and see if you can work from there.

hope this helps
Joel McNary
Bartender

Joined: Aug 20, 2001
Posts: 1815
The important lesson to learn here is that Nigel did not change the underlying code in the program...he kept the data types the same and simply changed the user interface to display 1's and 0's instead of trues and falses.

You could also then change it to display Y/N, T/F (or, for the really sadistic, A/B or even N/Y.....)

You might want to add a could of static variables:


If you were yo use these in the code, you could change the displays to whatever your heart desired with very little effort.


Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Another newbie question
 
Similar Threads
code segment question #2
Casting Boolean
How to modify this program to use & display 1s and 0s instead of true and false?
Help with program: Monty Hall Problem
assigning int types to a boolean expression