Tuesday, October 4, 2011

Java Programming Helper


Logic_Operators

1.  Given that the variables x and y have already been declared and assigned values, write an expression that evaluates to true if x is non-negative and y is negative.
Example:  So, if the value of x were 4 and the value of y were -3 then the expression would be true.
On the other hand, if the value of x were 4 and the value of y were 1 then the value of the expression would be false.

x >= 0 && y < 0

2.  Given that the variables x and y have already been declared and assigned values, write an expression that evaluates to true if  x is positive (including zero) or y is negative.

x >= 0 || y < 0

3.  Given two variables, isEmpty of type boolean, indicating whether a class roster is empty or not, and numberOfCredits of type int , containing the number of credits for a class, write an expression that evaluates to true if the class roster is empty or the class is exactly three credits.

isEmpty || numberOfCredits == 3

4.  Given two variables, isEmpty of type boolean, indicating whether a class roster is empty or not, and numberOfCredits of type int, containing the number of credits for a class, write an expression that evaluates to true if the class roster is not empty and the class is more than two credits.

!isEmpty && numberOfCredits > 2

5.  Given two variables, isEmpty of type boolean, indicating whether a class roster is empty or not, and numberOfCredits of type integer , containing the number of credits for a class, write an expression that evaluates to true if the class roster is not empty and the class is one or three credits.
Example:  So, if the value of isEmpty were false and the value of numberOfCredits were 3 then the expression would be true.
On the other hand, if the value of isEmpty were true or the value of numberOfCredits were 2 then the value of the expression would be false.

!isEmpty && (numberOfCredits == 1 || numberOfCredits == 3)




No comments:

Post a Comment