Lesson 5 - Activity 1 - Can you use doubles and variables?

Time: 15 minutes

Purpose: This activity helps you get familiar with using double number operators

Introduction: You’ve seen how to add two decimal numbers together - do you think you can try a few operations on your own?

Task: Perform the following operations on double variables and print the results,

  1. Divide one integer by another
  2. Subtract one integer from another
  3. Multiply one integer by another
    double decDivideTotal, devSubtractTotal, devMultiplyTotal;

    decDivideTotal = decNum1 / decNum2;
    devSubtractTotal = decNum1 - decNum2;
    devMultiplyTotal = decNum1 * decNum2;

    System.out.println("When we divide " + decNum1 + " by " + decNum2 + " we get: " + decDivideTotal);
    System.out.println("When we subtract " + decNum1 + " from " + decNum2 + " we get: " + devSubtractTotal);
    System.out.println("When we multiply " + decNum1 + " with " + decNum2 + " we get: " + devMultiplyTotal);

Yay - that looks right!