Ch 3 Questions #1

 

Conditional Statements

 

 

 

 

1.         What are the equality and relational operators in Java?

 

2.         What error would occur with the following statement?

 

            if (x = 7)

 

3.         How many statements following an if statement will executed if the if statement is true and there are no curly braces? if the if statement is false?

 

4.         What is necessary to have more than one statement executed following an if statement?

 

5.         What does the operator "!=" mean?

 

6.         What is the difference between an if statement and an if-else statement?

 

7.         How would you test two conditions in the same if statement?

 

8.         What is a truth table?

 

9.         Draw a truth table for the boolean variables x and y and all of their possible combinations.

 

10.       What will be printed by the following code fragment?  if flag = false; if flag = false and x = 1.  Explain your answers.

 

     boolean flag = true;

     int x = -1;

     if (flag && (X > 0))

          System.out.println ("YES");

     else if (x = 0)

          System.out.println ("MAYBE");

     else if (x = 0)

          System.out.println ("SOMETIMES");

     else

          System.out.println ("NO");