Hi to all! I'm glab to be here and...I'm here because I need some help! ^^; Hope someone can give me an hand...
I'm trying to study java using some books for beginners...and I gest stucked in an excercise... I've this:
class LogicalOpTable {
public static void main(String args[]) {
boolean p, q;
System.out.println("P\tQ\tAND\tOR\tXOR\tNOT");
p = true; q = true;
System.out.println(p + "\t" + q + "\t" + (p&q) + "\t" + (p|q) + "\t" + (p^q) + "\t" + (!p));
p = true; q = false;
System.out.println(p + "\t" + q + "\t" + (p&q) + "\t" + (p|q) + "\t" + (p^q) + "\t" + (!p));
p = false; q = true;
System.out.println(p + "\t" + q + "\t" + (p&q) + "\t" + (p|q) + "\t" + (p^q) + "\t" + (!p));
p = false; q = false;
System.out.print(p + "\t" + q + "\t" + (p&q) + "\t");
System.out.print((p|q) + "\t" + (p^q) + "\t" + (!p));
}
}
which stamp a table of true/false combination...
Now, I've to make a table like that BUT using 1 and 0 instead of true and false...the problem is that i cannot get "!p" works with integer, it return this error:
LogicalOpTable10.java:12: operator ! cannot be applied to int
System.out.println(!p + "\t" + q + "\t" + (p&q) + "\t" + (p|q) + "\t" + (p^q) + "\t" + (!p));
I've just read this thread that was about the same problem:
http://www.daniweb.com/software-development/java/threads/82507
But they not solved that problem at all! If I try what was said there, I got the same error....
so basically is "!p" (or "intP" for the other thread) the main problem (I think...)...I can't get it to work... someone can help me to solve this ? :| in a simple way if I can ask
Many thanks and sorry for my english, I'm improving!