Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Hi,

I am working one below challenge

http://codingbat.com/prob/p137742

how do i design this problem with flow chart etc and how to improve my design and implementation. please advise

I am working one below challenge

http://codingbat.com/prob/p137742

public boolean love6(int a, int b) {i am failing one test case

if((a==6||b==6)|(a+b==6)|(a-b==6))

{

return true;

}

else{

return false;

}

}

Expected Run

love6(6, 4) → true true OK

love6(4, 5) → false false OK

love6(1, 5) → true true OK

love6(1, 6) → true true OK

love6(1, 8) → false false OK

love6(1, 7) → true false X

love6(7, 5) → false false OK

love6(8, 2) → true true OK

love6(6, 6) → true true OK

love6(-6, 2) → false false OK

love6(-4, -10) → true true OK

love6(-7, 1) → false false OK

love6(7, -1) → true true OK

love6(-6, 12) → true true OK

love6(-2, -4) → false false OK

love6(7, 1) → true true OK

love6(0, 9) → false false OK

love6(8, 3) → false false OK

love6(3, 3) → true true OK

love6(3, 4) → false false OK

other tests

OK

how do i design this problem with flow chart etc and how to improve my design and implementation. please advise

Experts Exchange Solution brought to you by

Enjoy your complimentary solution view.

Get every solution instantly with premium.
Start your 7-day free trial.

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial```
return (a == 6) || (b == 6) || (Math.abs(a-b) == 6) || (a+b == 6);
```

Your more verbose version doesn't really add readability, so why not the above?

```
< a = 6 > ----(T)---+
| |
(F) |
| |
v |
< b = 6 > ----(T)---+
| |
(F) |
| |
v |
< a+b = 6 > ---(T)--+
| |
(F) |
| |
v |
< abs(a-b)=6 > -(T)-+
| |
v v
(F) (T)
```

Each <..> is decision with the condition inside. The path to the right is taken if the decision is true. The path down is taken if the decision is false. The terminals at the bottom are what is returned when control reaches that point (false or true).

Jim

```
return (Math.abs(Math.max(a,b)-Math.min(a,b))==6)||(a+b==6)?true:a==6||b==6?true:false;
```

```
return (Math.abs(Math.max(a,b)-Math.min(a,b))==6)||(a+b==6)?true:a+b-a==6||a+b-b==6?true:false;
```

ASCII flowchart

i like this. Where i can find more information on it. I never used it. Please advise

The question gave you a clue about using Math.abs(..)

i overlooked that point

Secondly, instead of using bitwise-OR you need to use ||

why is it preferred due to performance (where if it is false (or true) then does not bother to check next one whether true or false since result is anyway false?

(Math.abs(Math.max(a,b)-Math.min(a,b ))==6)||(a +b==6)?tru e:a+b-a==6 ||a+b-b==6 ?true:fals e;

above is not clear to me. please advise

||(a+b==6) then or condition(ie not bit or??)

?true:a+b-a==6||a+b-b==6?t

too confusing to me

Then why is anyone still posting anything else?

I might be wrong, but I think CEHJ was talking to *you* . ;)

```
return a+b==6||a-b==6||b-a==6||a+b-a==6||a+b-b==6;
```

Please advise

return a+b==6||a-b==6||b-a==6||a+b-a==6||a+ b-b==6;

in above line what is meaning of last part as below?

a+b-a==6||a+b-b==6(a+b-a means b right and same way a+b-b results in a right???not sure what we are conveying to compiler or to jvm whichever

other first part is clear which is a+b==6||a-b==6||b-a==6

Please advise

Eventually, yes; but at the outset . . . like perhaps now . . . it's best to understand one at a time, the if statement structure first - which all the guys here and in your others questions are masterful at, and then, after that, the ternary ops.

I

Java EE

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Experts Exchange Solution brought to you by

Enjoy your complimentary solution view.

Get every solution instantly with premium.
Start your 7-day free trial.

Open in new window

The question gave you a clue about using Math.abs(..)

Secondly, instead of using bitwise-OR you need to use ||