Review Exercises - Class 7

  1. Write a short Java code segment that uses an if-statment that reads a double from the user and writes its absolute value. The absolute value of a number leaves positive numbers alone and turns a negative number into its positive equivalent. For example the absolute value of -7.2 is 7.2. The absoulte value of 3.14159 is 3.14159.
  2. Write a short Java code segment that reads two integers from the user and prints the larger of the two.
  3. Write a Java code segment that generates a random integer of either 0 or 1 prints "zero" to the console if a 0 was generated or "one" if a 1 was generated.
  4. Write a Java code segment that reads three exam grades and prints A if the avergae was 90 or higher, B if 80 or higher, C if 70 or higher, D if 60 or higher, and F if below 60.