Welcome to Dream.In.Code
Become a Java Expert!

Join 149,485 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 1,339 people online right now. Registration is fast and FREE... Join Now!




I need java help for beginners.

 
Reply to this topicStart new topic

I need java help for beginners., I need java help for beginners.

ganni
21 Apr, 2007 - 08:51 PM
Post #1

New D.I.C Head
*

Joined: 21 Apr, 2007
Posts: 6


My Contributions
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 ?

User is offlineProfile CardPM
+Quote Post

vasdueva
RE: I Need Java Help For Beginners.
21 Apr, 2007 - 09:44 PM
Post #2

D.I.C Head
**

Joined: 3 Apr, 2007
Posts: 69


My Contributions
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.
CODE

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 Apr, 2007 - 09:45 PM
User is offlineProfile CardPM
+Quote Post

ganni
RE: I Need Java Help For Beginners.
21 Apr, 2007 - 10:06 PM
Post #3

New D.I.C Head
*

Joined: 21 Apr, 2007
Posts: 6


My Contributions
QUOTE(vasdueva @ 21 Apr, 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.
CODE

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!

User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/7/09 04:49PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month