Review for Exam 1

1. Define Primitive Data Type. List 4 primitive data types in Java.

2. Which takes up more memory, an int or a double?

3. Correct the following. Write no correction if the code is correct.

int val = 7.5;
double score = 89;
double avg = test1 + test2 /2;

4. What is output?

      System.out.println("Answer = " + 67 + 3); 

5. What characters do each of the following represent?

  • \n
  • \t
  • \\
  1. What characters are allowed in Java variable names?

  2. You have two integer variables, minutes and hours. Minutes moves up by one. update hour and minutes?

    1. minutes = minutes % 60;

    2. minutes = minutes + hours % 60;

    3. hours = hours + minutes / 60; minutes = minutes % 60;

    4. hours = hours + minutes % 60; minutes = minutes / 60;

    5. hours = hours + minutes / 60;

  3. Evaluate the following expressions:

    6%6 =
    8%6 =
    4%7 =
    6%3 =
    9%7 =

  4. What is roundoff error?

  5. Correct the following code so that it does not trigger roundoff error:

    double val = scan.nextDouble();
    System.out.println(val - 13.89);

11. When do you need to cast or when don't you? Give an example of each

need to cast
do not need to cast

12 Basic Demorgan's Law: What is

!( a || B),
!( X && Y),
!( c < d),
!( e>=f)

13 Use If/Else logic. Write the code to test if the int variable x has a value that is between 10 and 20 exclusive.

14. Basic binary conversion with numbers from 0-32 (no calculator needed)
1101 =
19 =