Skip to main content
Lesson 3 - Data Types in Java
ZIPPDF (letter)
Lesson MenuPreviousNext
  
L.A.3.1 - MathFun page 10 of 11

Background:

  1. For each primitive data type (such as int or double) there is a corresponding class (such as Integer or Double) in package java.lang. These classes (commonly known as wrapper classes) provide methods and constants for dealing with primitive data type values. Primitive data types do not have methods. Therefore, methods related to a primitive data type are located in the corresponding wrapper class.

  2. Some of the information provided by the wrapper classes are constants to indicate the largest and smallest values for a given data type. For example, the largest integer is 2147483647.

  3. Here are the names of the some of the constants associated with the wrapper classes for each data type:

    Byte.MAX_VALUE          // the largest value of type byte
    Byte.MIN_VALUE          // the smallest value of type byte
    Short.MAX_VALUE         // the largest value of type short
    Short.MIN_VALUE         // the smallest value of type short
    Character.MAX_VALUE     // the largest value of type char
    Character.MIN_VALUE     // the smallest value of type char
    Integer.MAX_VALUE       // the largest value of type int
    Integer.MIN_VALUE       // the smallest value of type int
    Long.MAX_VALUE          // the largest value of type long
    Long.MIN_VALUE          // the smallest value of type long
    Float.MAX_VALUE         // the largest positive value of type float
    Float.MIN_VALUE         // the smallest positive value of type float
    Double.MAX_VALUE        // the largest positive value of type double
    Double.MIN_VALUE        // the smallest positive value of type double

Assignment:

  1. Write a program to solve the math expressions shown below.

  2. The program must store each calculated result in an appropriate variable.

  3. The program must print out the math expression and results as follows:

      2 + 3 = 5
      17 % 4 = 1
  4. The program will display and solve the following problems:

    4 + 9               (double)25 / 4
    46 / 7              (int) 7.75 + 2
    46 % 7              (int) 'P'
    2 * 3.0             (char)105
  5. The code will look something like this:

    intAnswer = 4 + 9;
    System.out.println("4 + 9 = " + intAnswer);
  6. Print out all the constants listed in Background: Section 3. For example:

    System.out.println("The largest value of type int = " +
                               Integer.MAX_VALUE );

Instructions:

  1. After completing the program, print your source code and a run output to the printer.

  2. Make sure your name is documented near the top of your source code.


Lesson MenuPreviousNext
Contact
 ©ICT 2003, All Rights Reserved.