Chapter 3: Floating point Exercises

Find the errors in problems 1 through 8 and fix them if possible

1. if quarters > 0 then System.out.println(quarters + " quarters");
2. if (1 + x > Math.pow(x, Math.sqrt(2)) y = y + x;
3. if (x  =  1) y++;   else if  (x  =  2)   y  =  y  +  2;
4. if (x  && y  ==  0)   { x  =  1; y  = 1; }
5. if  (1 <=   X   <=  10) 
       System.out.println(x);
6. if (s !=  "nickels" || s  !=  "pennies"
      || s  !=  "dimes" || s  !=  "quarters")
      System.out.print("Input error!");
7. if (input.equalsIgnoreCase("N") || "NO")
      return;
8. int x  =  Integer.parseInt(input);
   if (x ! = null) y  =  y  +  x;
9. Write a truth table for the following boolean expressions and compare them: 

Complete the table below.
  p     q     r    (p && q) || !r     !(p && (q || !r))
  f     f     f
  f     f     t
  f     t     f
       ...
  5 more combinations

Programming Assignments:

1 . Write a program that reads in three floating-point numbers and prints the three inputs in sorted order. For example:

Please enter  three  numbers:
  4
  9
  2.5
The  inputs in sorted order are
  2.5
  4
  9

2. Write a Java program, CompareFloats_YI.java to show two floating-point numbers x and y such that Math.abs(x – y) is larger than 1000, but x and y are still identical except for a round­ off error.