Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Java (from the \"Java Illuminated\" book 4th Edition) Chapter 5 page 264 #\'s 1-

ID: 3663606 • Letter: J

Question

Java (from the "Java Illuminated" book 4th Edition) Chapter 5 page 264 #'s 1-3, 39 and 44 ; Chapter 6 page #'s 356 1-3, 5 and 8

****page 264 1-3; 39 and 44

1. Given the following code declaring and initializing two int variables a and b with respective values 3 and 5, indicate whether the value of each expression is true or false.

            int a = 3;

           int b = 5;

   EXPRESSION         True             False

a < b                         ______         ______

a != b                        ______        ______

a == 4                       ______        ______

(b - a) <= 1               ______         ______

Math.abs(a - b) >= 2 ______         ______

(b % 2 == 1)             ______         ______

b <= 5                       ______         ______

2. Given the following code declaring and initializing three boolean variables a, b, and c, with respective values are true, true, and false, indicate whether the value of each expression is true or false.

            boolean a = true;

            boolean b = true;

            boolean c= false;

  EXPRESSION                      True                False

           !a                               ______           ______

            a && b                      ______           ______

            a && c                       ______           ______

            a || c                          ______           ______

            ! (a || b)                     ______           ______

            !a|| b                         ______           ______

            !( ! ( a && c))            ______           ______

           a && !(b || c)             ______           ______

3. Given two boolean variables a and b, are the following expressions equivalent?

          ______    !(!a)

          ______     a

39. You coded the following in class Test.java:

       boolean b = true ;

      if ( b )

          System.out.println( "Inside true block" );

          System.out.println( "b was true" );

     else         //line 12

           System.out.println( "Inside false block" );

**{At compile time, you get the following error:}

    Test.java:12: error: 'else' without 'if'

    else        //line 12

    ^

1 error

Explain what the problem is and how to fix it.

44. Write a aprogram that caculates the area of the following figures:

             * a square of side 0.666666667

             * a rectangle of sides 1/9 and 4

****Page 356 1-3; 5 and 8

1. How do you discover that you have an infinite loop in your code?

   ______ The code does not compile.

   ______ The code compiles and runs but gives the wrong result.

   ______ The code runs forever.

   ______ The code compiles, but there is a run-time error.

2. If you want to execute a loop body at least once, what type of loop would you use.

   ______ for loop

   ______ while loop

   ______ do/while loop

   ______ none of the above

3. What best describe a for loop?

   ______ It is a count- controlled loop.

   ______ It is an event- controlled loop.

   ______ It is a sential- controlled loop.

5. What is the output of this code sequence? (The user successively enters 3, 5, and -1.)

          System .out.print( "Enter an int > " );

          int i = scan.nextInt();

          while ( i != -1 )

           {

                System.out.println( "Hello" );

                System.out.print( "Enter an int > " );

8. What are the values of i and sum after this code sequence is excuated?

            int sum = 0;

            int i = 17;

            while ( i % 10 != 0 )

           {

               sum += i;

               i++;

          }

Explanation / Answer

1.
   a. true
   b. true
   c. false
   d. false
   e. true
   f. true
   g. true

2.
   a. fasle
   b. false
   c. true
   d. false
   e. true
   f. false
   g. false

3. yes

39.
   boolean b = true ;
if ( b )
{
System.out.println( "Inside true block" );
System.out.println( "b was true" );
}
else //line 12
System.out.println( "Inside false block" );

44.
class area
{
   public static void main(String args[])
   {
       double s=0.66666, l=0.1111, b=4;

       System.out.println("Area of Square is " + (s*s));
       System.out.println("Area of Rectangle is "+(l*b));
   }
}


1.   
The code runs forever.

2.
do/while loop

3.
It is a count- controlled loop.

5.
Hello
Hello

8.
i=20
sum=54

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote