# Necklace application in java

Page 1 of 1

## 5 Replies - 184 Views - Last Post: 28 November 2017 - 02:42 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=407901&amp;s=3e6b22c0aa53aa16257b105ae81d24bd&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 DumbProgrammer01

Reputation: 0
• Posts: 5
• Joined: 27-November 17

# Necklace application in java

Posted 28 November 2017 - 12:19 PM

i need help understanding the necklace problem. We're supposed to make a application that prompts the user for two single-digit integers and the displays the sequence and the number of steps taken. Please help. Also i need help to print out the number

nt N1;
int N2;
int Sum;
int num;
int Pn;
int NN;
int counter = 0;
Scanner input = new Scanner(System.in);
System.out.print("Enter the first Starting number: ");
N1 = input.nextInt();
System.out.print("Enter the second starting number: ");
N2 = input.nextInt();

Sum = N1 + N2;
NN = Sum%10;
Pn = N2;
while  ((Pn != N1) || (NN != N2));
{
Sum = NN + Pn;
Pn = NN;
System.out.print(NN);
NN = Sum % 10;

}
System.out.print("Number of steps was: " +counter);
}

This post has been edited by modi123_1: 28 November 2017 - 12:50 PM
Reason for edit:: In the future, please use the [code] tag button in the editor.

Is This A Good Question/Topic? 0

## Replies To: Necklace application in java

### #2 modi123_1

• Suitor #2

Reputation: 13666
• Posts: 54,541
• Joined: 12-June 08

## Re: Necklace application in java

Posted 28 November 2017 - 12:20 PM

### #3 DumbProgrammer01

Reputation: 0
• Posts: 5
• Joined: 27-November 17

## Re: Necklace application in java

Posted 28 November 2017 - 12:38 PM

modi123_1, on 28 November 2017 - 07:20 PM, said:

When i run the program is won't show the necklace problem, but i think it is bc i need to print out the number but i dont know how to do that and i also new to java

### #4 modi123_1

• Suitor #2

Reputation: 13666
• Posts: 54,541
• Joined: 12-June 08

## Re: Necklace application in java

Posted 28 November 2017 - 12:51 PM

If you need to print something out you certainly can do that inside the while loop.

### #5 DumbProgrammer01

Reputation: 0
• Posts: 5
• Joined: 27-November 17

## Re: Necklace application in java

Posted 28 November 2017 - 02:40 PM

modi123_1, on 28 November 2017 - 07:51 PM, said:

If you need to print something out you certainly can do that inside the while loop.

Thank you so much, that helps a lot

### #6 modi123_1

• Suitor #2

Reputation: 13666
• Posts: 54,541
• Joined: 12-June 08

## Re: Necklace application in java

Posted 28 November 2017 - 02:42 PM

You're welcome! Sometimes it is the little things.

It also helps when you don't have a semi colon after the while loop condition.. doing that detaches the while body from the condition.

17        while  ((Pn != N1) || (NN != N2));