Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

>> REGISTER NOW TO START POSTING

# Thread: help with necklace problem?

1. ## help with necklace problem?

So the program begins with two single digit numbers. The next number is obtained by adding the first two numbers together and saving only the ones digit. This process is repeated until the necklace closed by returning to the original two numbers. For example, starting from the two numbers 1 and 8, we get: 1 8 9 7 6 3 9 2 1 3 4 7 1 8

Here's what I have so far:
```import java.util.Scanner;

class test {
public static void main(String args[]){
Scanner input = new Scanner(System.in);

int num1,num2,sum;

System.out.print("Enter the first starting number: ");
num1 = input.nextInt();

System.out.print("Enter the second starting number: ");
num2 = input.nextInt();

int sum1 = num1+num2;
int total = sum1 + num2;

int ones = total %10;

System.out.print(num1 + " ");
System.out.print(num2 + " ");
System.out.print(sum1+ " ");
System.out.print(ones+ " ");

}
}```
I got the basic algorithm right, but now I need to put this in a loop. How would I do it?

2. ## Re: help with necklace problem?

So you need to know when to stop looping. Any ideas how you might do that?

3. ## Re: help with necklace problem?

no, and btw I'm new to java programming.

4. ## Re: help with necklace problem?

Originally Posted by namenamename
no
If you have absolutely zero idea how to do anything in programming then you should give up. If you walk away from the computer and took some time to think about how you can do this on paper then you do have some idea how to do it.

Do you know how to declare variables?
Do you know how to compare variables?
Do you know how to assign and change the value in variables?

Once again you do have some idea how to do this.

I'm new to java programming.
You are not new. I've seen you posting in the past.