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.
 
 
 
 
 
 
zanninso 0bcd6a5187
DEV-4788-HelloWorld-Java-Exercise (#1958)
1 year ago
..
README.md DEV-4788-HelloWorld-Java-Exercise (#1958) 1 year ago

README.md

IntOperations

Instructions

Create a file IntOperation.java.

Write a function addTwoIntegers that returns the sum of two integers passed as parameter. Write a function substractTwoIntegers that returns subtraction of two integers passed as parameter. Write a function multiplyTwoIntegers that returns the multiplication of two integers passed as parameter. Write a function divideTwoIntegers that returns the Euclidian division of two integers passed as parameter. We ignore the divide by 0 case.

Expected Functions

public class IntOperation {
    public static int addTwoIntegers(int a, int b) {
        // your code here
    }
    public static int subtractTwoIntegers(int a, int b) {
        // your code here
    }
    public static int multiplyTwoIntegers(int a, int b) {
        // your code here
    }
    public static int divideTwoIntegers(int a, int 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(IntOperation.addTwoIntegers(1, 2));
        System.out.println(IntOperation.addTwoIntegers(15, 68));

        System.out.println("Subtract");
        System.out.println(IntOperation.subtractTwoIntegers(4, 1));
        System.out.println(IntOperation.subtractTwoIntegers(10, 23));

        System.out.println("Multiply");
        System.out.println(IntOperation.multiplyTwoIntegers(3, 6));
        System.out.println(IntOperation.multiplyTwoIntegers(12, 11));

        System.out.println("Divide");
        System.out.println(IntOperation.divideTwoIntegers(8, 2));
        System.out.println(IntOperation.divideTwoIntegers(13, 4));
    }
}

and its output :

$ javac *.java -d build
$ java -cp build ExerciseRunner
Add
3
83
Subtract
3
-13
Multiply
18
132
Divide
4
3
$

Notions

Primitive Links
Operations