I already posted this question but I gave it a try I'm not sure if I'm on the right track:
Make a util class with three methods. First method's name is add, that returns the result by adding two numbers.
Second method's name is multiply, that returns the result by multiplying two numbers.
Third's method name is division that returns a result by dividing first parameter by second parameter. How would I do this part?
This is what I've got so far:
public class Util {
public static int add(int a, int b){
int result = a + b;
System.out.println("result = " + result);
return result;
}
public static void main(String[] args) {
int res = add(5, 2);
System.out.println("res = " + res);
}
public static int multiply(int a, int b){
int result = a * b;
System.out.println("result = " + result);
return result;
}
public static void main(String[] args) {
int res = multiply(5, 2);
System.out.println("res = " + res);
}
}
3 answers
Do a division in the same way. Just copy the multiply routine, and replace * with /.
Be sure to watch out for division by zero.