I hope you are well.In last tutorial we are learning how to take input from keyboard.Today we will learning about Boolean operators.
Boolean operators are true and false .
By seeing next table we all will understand about boolean operator.Here it is.....
A
|
B
|
A|B
|
A&B
|
A^B
|
!A
|
false
|
false
|
false
|
false
|
false
|
true
|
false
|
true
|
true
|
false
|
true
|
true
|
true
|
false
|
true
|
false
|
true
|
false
|
true
|
true
|
true
|
true
|
false
|
false
|
also: !true = false and !false = true.
you will better known if you complete discrete mathematics.
here is a example:
public class BoolLogic {
public static void main(String args[]){
boolean A = true;
boolean B = false;
boolean C = A|B;
boolean D = A&B;
boolean E = A^B;
boolean F = !A;
boolean G = (!A&B)|(A&!B);
System.out.println(" A = " + A);
System.out.println(" B = " + B);
System.out.println(" C = " + C);
System.out.println(" D = " + D);
System.out.println(" E = " + E);
System.out.println(" F = " + F);
System.out.println(" G = " + G);
}
}
result:
B = false
C = true
D = false
E = true
F = false
G = true
So try this example.
Here another example for you.I hope it will clear you more.
import java.util.Scanner;
public class testbooleans {
public static void main(String args[]){
Scanner pavel = new Scanner(System.in);
System.out.println("Enter an integer number");
int i = pavel.nextInt();
System.out.println("Enter another integer number");
int j = pavel.nextInt();
boolean b;
b = i>j;
if(b)
System.out.println("First number is MAXIMUM");
else
System.out.println("Last number is maximum");
}
}
Now input tow number.then see it will work.
if(b) means that if the
b = i>j; statement is true then it it will.unless else
Today we stopped here.Till next tutorial Best of Luck.
0 comments:
Post a Comment