5 Replies - 244 Views - Last Post: 28 November 2017 - 02:42 PM Rate Topic: -----

#1 DumbProgrammer01   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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);
    }
:code:

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   User is online

  • Suitor #2
  • member icon



Reputation: 14146
  • View blog
  • Posts: 56,699
  • Joined: 12-June 08

Re: Necklace application in java

Posted 28 November 2017 - 12:20 PM

What is your question?
Was This Post Helpful? 0
  • +
  • -

#3 DumbProgrammer01   User is offline

  • New D.I.C Head

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

Re: Necklace application in java

Posted 28 November 2017 - 12:38 PM

View Postmodi123_1, on 28 November 2017 - 07:20 PM, said:

What is your question?

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
Was This Post Helpful? 0
  • +
  • -

#4 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 14146
  • View blog
  • Posts: 56,699
  • 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.
Was This Post Helpful? 0
  • +
  • -

#5 DumbProgrammer01   User is offline

  • New D.I.C Head

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

Re: Necklace application in java

Posted 28 November 2017 - 02:40 PM

View Postmodi123_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
Was This Post Helpful? 0
  • +
  • -

#6 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 14146
  • View blog
  • Posts: 56,699
  • 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));

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1