I have ltp and s1 , s2 and s3 values
(s1 , s2 , s3 denotes suppourt1 , suppourt2 , suppourt3 )
What I am trying to achieve is that ,
If the ltp is 2 points near S1 , display S1
If the ltp is 2 points near S2 , display S2
If the ltp is 2 points near S3 , display S3
I have tried using this
public class Test {
public static void main(String[] args) {
double ltp = 15.45;
double s1 = 18.34;
double s2 = 16.34;
double s3 = 10.34;
double s1Level = ltp - s1;
double s2Level = ltp - s2;
double s3Level = ltp - s3;
if (s1Level <= 2) {
System.out.println("S1");
}
else if (s2Level <= 2) {
System.out.println("S2");
}
else if (s3Level <= 2) {
System.out.println("S3");
}
}
}
Here ltp is 15.45 and its near s2 16.34 , I was expecting S2.
if (s1Level >= -2 && s1Level <= 2)else ifwon't help if all the deltas are within the range. Which one do you want? The smallest? Largest? All of them?