Results 1 to 6 of 6
  1. #1
    Sanna.1 is offline Member
    Join Date
    Feb 2012
    Posts
    5
    Rep Power
    0

    Default 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. #2
    j_arif123 is offline Member
    Join Date
    Jan 2012
    Location
    India
    Posts
    34
    Rep Power
    0

    Default Re: Boolean exercise

    I think this would help you:

    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. #3
    Sanna.1 is offline Member
    Join Date
    Feb 2012
    Posts
    5
    Rep Power
    0

    Default 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. #4
    j_arif123 is offline Member
    Join Date
    Jan 2012
    Location
    India
    Posts
    34
    Rep Power
    0

    Default Re: Boolean exercise

    Quote Originally Posted by Sanna.1 View Post
    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. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,014
    Rep Power
    20

    Default Re: Boolean exercise

    Quote Originally Posted by j_arif123 View Post
    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. #6
    j_arif123 is offline Member
    Join Date
    Jan 2012
    Location
    India
    Posts
    34
    Rep Power
    0

    Default 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?

Similar Threads

  1. Replies: 3
    Last Post: 09-13-2011, 12:01 AM
  2. boolean error help when no boolean is given
    By drewtrcy in forum New To Java
    Replies: 18
    Last Post: 05-05-2011, 09:04 AM
  3. Have I done this exercise right?
    By ccie007 in forum New To Java
    Replies: 7
    Last Post: 09-28-2010, 05:54 PM
  4. I/O exercise
    By Feldom in forum New To Java
    Replies: 1
    Last Post: 10-28-2007, 04:48 PM
  5. help with exercise
    By e_as're in forum New To Java
    Replies: 3
    Last Post: 09-25-2007, 10:14 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •