I am working my way through previous exam papers trying to build my experience in Java. There are two answers to this particular question. The first is my own which seems straight forward and the second is that of my lecturer, which seems confusing to me at this particular stage of my Java development.
Here is my code:
public class InClassTestTwoQ2
{
public static void main(String[] args){
double sum = 3.14;
System.out.println(test(sum));
System.out.println(testTwo(sum));
}
public static boolean test(double sum){
return sum != 3.14; //My boolean test return type
}
public static boolean testTwo(double sum){
return Math.abs(sum - 3.14) > 1e-14; //Lecturer boolean test return type
}
}
Is using Math.abs a better option here? Also, I am not sure what the 1e-14 is doing? Can someone explain any possibilities as to why my lecturer has returned his boolean statement this way? Mine seems straight forward where as I would have never done it his way?
Also, please forgive any errors in my code. I am still learning Java. Many thanks.