You may also want to think about how you are doing the range 30..40 inclusive and range 40..50 inclusive tests
public boolean in3050(int a, int b) {
if((Math.abs(a-30)>=10 &&Math.abs(b-30)>=10) || (Math.abs(a-40)>=10&& Math.abs(b-40)>=10))
{
return true;
}
if((Math.abs(a-40)>=10 && Math.abs(b-40)>=10) || (Math.abs(a-50)>=10 && Math.abs(b-50)>=10))
{
return true;
}
return false;
}
I have couple of test cases failing as belowpublic boolean in3050(int a, int b) {
if((Math.abs(a-30)>=10 &&Math.abs(b-30)>=10) || (Math.abs(a-40)>=10&& Math.abs(b-40)>=10))
{
return true;
}
if((Math.abs(a-40)>=10 && Math.abs(b-40)>=10) || (Math.abs(a-50)>=10 && Math.abs(b-50)>=10))
{
return true;
}
if((a-50)>=1 && (b-50)>=1)
{
return false;
}
return false;
}
public class Test9 {
public static void main(String[] args) {
// TODO Auto-generated method stub
in3050(40,51);
}
public static boolean in3050(int a, int b) {
if((Math.abs(a-30)<=10 &&Math.abs(b-30)<=10) || (Math.abs(a-40)<=10&& Math.abs(b-40)<=10))
{
return true;
}
if((Math.abs(a-40)<=10 && Math.abs(b-40)<=10) || (Math.abs(a-50)<=10 && Math.abs(b-50)<=10))
{
return true;
}
if((a-50)>0 && (b-50)>0)
{
return false;
}
return false;
}
}
public boolean in3050(int a, int b) {
if ( (a>=30 && a<=40) && (b>=30 && b<=40) ) { // a and b in the range 30...40?
return true; // Yes!
}
if ( (a>=40 && a<=50) && (b>=40 && b<=50) ) { // a and b in the range 40...50?
return true; // Yes!
}
return false; // no succes (otherwhise, we shouldn't have come till here)
}
public class Test8 {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
boolean b=in3050(30, 51);
System.out.println("b is-->"+b);
}
public static boolean in3050(int a, int b) {
if ( a>=30 && a<=40 && b>=30 && b<=40 ) { // a and b in the range 30...40?
return true; // Yes!
}
if ( a>=40 && a<=50 && b>=40 && b<=50 ) { // a and b in the range 40...50?
return true; // Yes!
}
return false; // no succes (otherwhise, we shouldn't have come till here)
}
}
If you are experiencing a similar issue, please ask a related question
Title | # Comments | Views | Activity |
---|---|---|---|
Java array passed to SQL where clause | 23 | 62 | |
ArrayIndexOutOfBoundExcept |
9 | 66 | |
java jdbc batch example | 8 | 20 | |
java stored proc example | 9 | 20 |
Join the community of 500,000 technology professionals and ask your questions.
Connect with top rated Experts
21 Experts available now in Live!