1. Member
Join Date
Feb 2012
Posts
5
Rep Power
0

## Boolean exercise

hi every one

I have a exercise when i going to use boolean.

Im need to do 3 intergervaribals var1 var2 var3 and then i get same claim im going to get in to it like one of it is: The number var1 is evenly divisible by 7.

i figuer out that i can use samthing like this.
boolean sv = (var1%7 == 0);
System.out.println(sv);
i know how to do the boolean and look if its true or not but i dont know how to use it when im going to get 3 diffrent intergervaribals

plz can anyone show my how you type this program so i can understand it. and its only a exercise so i dont need to show it to anyone its only for my self to learn, so its no real homework that

2. Member
Join Date
Jan 2012
Location
India
Posts
34
Rep Power
0

## Re: Boolean exercise

Java Code:
```class booleantest	{
public static void main(String args[])	{
int var1 = 49;
boolean sv = (var1 % 7 == 0);
System.out.println("\n sv = " + sv);
}
}```
The Output is :
sv = true

From this it is clear that relational operator == returns exactly the word true or false . For three variables such as var1,var2,var3 , the program will be :

Java Code:
```class booleantest	{
public static void main(String args[])	{
int var1 = 49;
int var2 = 50;
int var3 = 14;
boolean b1 = (var1 % 7 == 0); // true
boolean b2 = (var2 % 7 == 0); // false
boolean b3 = (var3 % 7 == 0); // true

if( b1 && b2 && b3)
System.out.println("\n All the three variables are divisible by 7" );
else
System.out.println("\n one or two or all variables is or are [B]not[/B] divisible by 7" );

}
}```
&& is logical operator used to combine boolean expressions or terms. if any one of values is false , entire expression is evaluated as false.

3. Member
Join Date
Feb 2012
Posts
5
Rep Power
0

## Re: Boolean exercise

thx for the help know i only need to figuer it out when you type in the numbers in your self:P

4. Member
Join Date
Jan 2012
Location
India
Posts
34
Rep Power
0

## Re: Boolean exercise

Originally Posted by Sanna.1
thx for the help know i only need to figuer it out when you type in the numbers in your self:P
what do you mean? i can not get you. Do you want to read values for the three variables from keyboard? or Please point it out clearly.

5. Moderator
Join Date
Apr 2009
Posts
11,820
Rep Power
19

## Re: Boolean exercise

Originally Posted by j_arif123
From this it is clear that relational operator == returns exactly the word true or false .
No it doesn't.
It returns a boolean, not a word (which implies a String).

6. Member
Join Date
Jan 2012
Location
India
Posts
34
Rep Power
0

## Re: Boolean exercise

Thanks for pointing out this . i meant that values of a boolean type are true , false . I learnt that java has these two as keyword . Do you know the Number of bits occupied by a boolean type?