Thursday, 23 October 2014

How to find close to 100 number

public class CloseTo100 {

    public static int findNearestNumbers(int in1,int in2){

    int in1Diff =    Math.abs(100-in1);
    int in2Diff =    Math.abs(100-in2);
if(in1Diff<in2Diff){
    return in1;
}else if(in1Diff>in2Diff){
    return in2;
}else{
    return in1;
}
    }
    public static void main(String[] args) {
System.out.println(CloseTo100.findNearestNumbers(95, 104));
    }

}

No comments:

Post a Comment