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:
- Create a new project named SimpleCalculations.
- In the
main( )method, declare the following:
int firstNumber
int secondNumber - Next, declare the following and employ the correct calculation methods for each respective mathematical operator:
float sum
float difference
float product
float quotient - Use the
(float)function to convert the int values tofloatvalues. You will know if this is done correctly if your values print as decimals. - 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); - 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