You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

1.4 KiB

FloatOperations

Instructions

Create a file FloatOperations.java.

Write the following functions:

  • Write a function divideTwoFloats that returns the float division of two floats passed as parameter.
  • Write a function addTwoFloats that returns the sum of two floats passed as parameter.

Expected Functions

public class FloatOperations {
    public static float addTwoFloats(float a, float b) {
        // your code here
    }
    public static float divideTwoFloats(float a, float b) {
        // your code here
    }
}

Usage

Here is a possible ExerciseRunner.java to test your function :

public class ExerciseRunner {
    public static void main(String[] args) {
        System.out.println("Add");
        System.out.println(FloatOperations.addTwoFloats(1.0f, 2.5f));
        System.out.println(FloatOperations.addTwoFloats(15.18f, 68.28347f));

        System.out.println("Divide");
        System.out.println(FloatOperations.divideTwoFloats(7.0f, 2.0f));
        System.out.println(FloatOperations.divideTwoFloats(5.6f, 6.9f));
    }
}

and its output :

$ javac *.java -d build
$ java -cp build ExerciseRunner
Add
3.5
83.46347
Divide
3.5
0.8115942
$

Notions

Primitive Links
Operations