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)
}
}
Title | # Comments | Views | Activity |
---|---|---|---|
Specific format | 21 | 142 | |
Unable to open debugger port in Intellij idea | 6 | 85 | |
Hibernate Not Rolling Back When something fails in a stored procedure | 2 | 37 | |
Java - Why doesn't this JFrame work | 3 | 18 |
Join the community of 500,000 technology professionals and ask your questions.
Connect with top rated Experts
19 Experts available now in Live!