Hi. I have a problem. I am totally beginner in Java. Now I'm learning Loops. please help me!

a+b+c=15 then a, b, c=? (PS: a, b and , c are not equal each other)

how can I solve this Problem Please help me?

a+b+c=15; then a , b and c are not equal each other. And a, b and c must be from 1 to 9. then find a=? b=? c=?

i think i should use 3 for loops. but i can't solve.

it can implement

1+5+9=15

1+6+8=15

1+8+6=15

1+9+5=15

2+4+9=15

2+5+8=15

2+6+7=15

2+8+5=15

2+9+4=15

................

...............

9+2+4=15

9+4+2=15

Help ?

## 2 Replies - 1597 Views - Last Post: 21 April 2007 - 11:06 PM

##
**Replies To:** I need java help for beginners.

### #2

## Re: I need java help for beginners.

Posted 21 April 2007 - 10:44 PM

all you can do is provide every possible solution. Here is a way to do it with loops. As you can see it starts with a= 0, it then enters the "b" loop with b = 0 lastly it enters the "c" loop starting with c = 0.

It will loop through for every possible combination of values. And print the ones that add up to 15.

It will loop through for every possible combination of values. And print the ones that add up to 15.

A=1; while(A <= 9) { B = 1; while(B <= 9) { C = 1; while(C <= 9) { if(A + B + C == 15) { System.out.print ln("A:" + A + " B:" + B + " C:" + C); } C++; } B++; } A++; }

This post has been edited by **vasdueva**: 21 April 2007 - 10:45 PM

### #3

## Re: I need java help for beginners.

Posted 21 April 2007 - 11:06 PM

vasdueva, on 21 Apr, 2007 - 10:44 PM, said:

all you can do is provide every possible solution. Here is a way to do it with loops. As you can see it starts with a= 0, it then enters the "b" loop with b = 0 lastly it enters the "c" loop starting with c = 0.

It will loop through for every possible combination of values. And print the ones that add up to 15.

It will loop through for every possible combination of values. And print the ones that add up to 15.

A=1; while(A <= 9) { B = 1; while(B <= 9) { C = 1; while(C <= 9) { if(A + B + C == 15) { System.out.print ln("A:" + A + " B:" + B + " C:" + C); } C++; } B++; } A++; }

Thank you very much! vasdueva!

Page 1 of 1