Lesson 5a - Simple Calculations

Follow these instructions to create your first program from the ground up (more or less).

We are going to create a simple program that calculates the values of int and returns them as float. Include the following in your program:

  1. Create a new project named SimpleCalculations.
  2. In the main( ) method, declare the following:
    int firstNumber
    int secondNumber
  3. Next, declare the following and employ the correct calculation methods for each respective mathematical operator:
    float sum
    float difference
    float product
    float quotient
  4. Use the (float) function to convert the int values to float values. You will know if this is done correctly if your values print as decimals.
  5. Display each calculation using a print line statement. Use the structure: "The sum of __ and __ is __." You will have to use the following structure:
    System.out.println("The sum of " + firstNumber + " and "
    + secondNumber + " is " + sum);
  6. Create an opening and closing statement that states that your program is beginning and ending.

Next Lesson: Lesson 5b - Suggested Practice Problems

Table of Contents: Table of Contents

Sample Code - SimpleCalculations