I need java help for beginners.

I need java help for beginners.

Page 1 of 1

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

#1 ganni  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 8
  • Joined: 21-April 07

I need java help for beginners.

Posted 21 April 2007 - 09:51 PM

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 ?

Is This A Good Question/Topic? 0
  • +

Replies To: I need java help for beginners.

#2 vasdueva  Icon User is offline

  • D.I.C Head

Reputation: 15
  • View blog
  • Posts: 141
  • Joined: 03-April 07

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.
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

Was This Post Helpful? 0
  • +
  • -

#3 ganni  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 8
  • Joined: 21-April 07

Re: I need java help for beginners.

Posted 21 April 2007 - 11:06 PM

View Postvasdueva, 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.
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!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1