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


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: help with necklace problem?

  1. #1
    Member
    Join Date
    Oct 2013
    Posts
    30
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: help with necklace problem?

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

  3. #3
    Member
    Join Date
    Oct 2013
    Posts
    30
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: help with necklace problem?

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

  4. #4
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: help with necklace problem?

    Quote Originally Posted by namenamename View Post
    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.
    Improving the world one idiot at a time!

Similar Threads

  1. Problem with Project Euler problem 18
    By sara_magdy in forum What's Wrong With My Code?
    Replies: 2
    Last Post: July 19th, 2013, 12:46 PM
  2. Replies: 3
    Last Post: January 5th, 2012, 01:44 AM
  3. [SOLVED] [Problem] imports javax.swing problem
    By Brollie in forum AWT / Java Swing
    Replies: 8
    Last Post: July 5th, 2009, 07:59 AM
  4. Java program for 2-D Array Maze
    By Peetah05 in forum Collections and Generics
    Replies: 11
    Last Post: May 8th, 2009, 04:30 AM