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:

Code :

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?

Re: help with necklace problem?

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

Re: help with necklace problem?

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

Re: help with necklace problem?

Quote:

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.

Quote:

I'm new to java programming.

You are not new. I've seen you posting in the past.