Write a public static method called subtractor that takes 2
Write a public static method called \"subtractor\" that takes 2 doubles as input parameters. This method subtracts the 1st parameter from the 2nd. If the result is negative the method returns zero. Otherwise it returns the result. Don\'t print anything. Only one return statement.
Solution
SubstractTest.java
public class SubstractTest {
public static void main(String[] args) {
System.out.println(subtractor(4,5));
System.out.println(subtractor(5.5,4.4));
}
public static double subtractor(double a, double b){
double result = b - a;
if(result <= 0){
return 0;
}
else{
return result;
}
}
}
Output:
1.0
0.0
