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 10 of 10

Thread: Stuck on 12 node star assignment

  1. #1
    Junior Member
    Join Date
    Sep 2014
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Stuck on 12 node star assignment

    Hi I am doing an assignment in my Java class and I need to connect the nodes to make a 12 pointed star. I have already drawn out the star and figured out which nodes to connect together. The only thing I cannot get is to show all of the nodes in the order they connect. I can only get the first 3 nodes to show up. I need it to wrap around and basically keep adding 5 to the last node until all numbers 0-11 are used. Any suggestions on what I can do to make that happen? I feel like it is one little bit of code I need to put in but I cannot figure out what it is.

    public class StarWinding {
    	public static void main(String[] args) {
    		for (int i = 0 ; i < 12; i+=5) {
    			System.out.print(i + " ");
     
    			}
    	}
    }

    And the out put so far is: 0 5 10
    I need it to be: 0 5 10 3 8 1 6 11 4 9 2 7
    Last edited by Slipd0wn; September 17th, 2014 at 08:27 PM.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Stuck on 12 node star assignment

    I need it to be: 0 5 10 3 8 1 6 11 4 9 2 7
    What is the logic for generating that sequence of numbers?

    Please edit your post and wrap your code with code tags:
    [code=java]
    YOUR CODE GOES HERE
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Sep 2014
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Stuck on 12 node star assignment

    Because I have a 12 pointed star and each point is numbered. You have to create a 12 pointed star by connecting these numbered points together. If you just connect the points in order you get a 12 sided-gram and not a star. I need the code to wrap back to zero and keep adding by 5. Example: 10 + 5 = 3 because 11, 0, 1, 2, 3. the highest it goes is 11 and then needs to start over at 0 and keep counting.

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

    Default Re: Stuck on 12 node star assignment

    When you add 5 to 10 you get 15 which is greater than 12 and your loop exits. You will need to rethink your design. Maybe a while loop would be better. To wrap your values back around to 0 you can use a circular counting pattern or simply subtract 12 when value is greater than 12.
    Improving the world one idiot at a time!

  5. #5
    Junior Member
    Join Date
    Sep 2014
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Stuck on 12 node star assignment

    I understand what you are saying Junky... I just do not know how to perform that operation in Java.

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

    Default Re: Stuck on 12 node star assignment

    What function? Subtraction?
    Improving the world one idiot at a time!

  7. #7
    Junior Member
    Join Date
    Sep 2014
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Stuck on 12 node star assignment

    I cannot just subtract 12 it will not work out. I don't know how to wrap my values back to 0. that is my whole problem.

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Stuck on 12 node star assignment

    Perhaps you need two variables: one to count to 12 and one to hold the value to print.
    If you don't understand my answer, don't ignore it, ask a question.

  9. #9
    Junior Member
    Join Date
    Sep 2014
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Stuck on 12 node star assignment

    so I have the one to count to 11 because it is 0-11 i do not know how to make one to hold the value to print

  10. #10
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Stuck on 12 node star assignment

    i do not know how to make one to hold the value to print
    I'm surprised that you don't know how to define a variable and give it an initial value. An example:
      int valToPrint = 0;   // define a variable to hold the value to print
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. [SOLVED] Beginner Java Course, Stuck on my First Assignment. Help Needed.
    By jlcarrillo in forum Object Oriented Programming
    Replies: 5
    Last Post: February 18th, 2018, 07:37 PM
  2. Help me with my 1st Java Assignment! Stuck!!
    By adnan.alvee in forum What's Wrong With My Code?
    Replies: 4
    Last Post: February 2nd, 2013, 07:55 PM
  3. Introduction to programing class. I am stuck on my assignment arrays.
    By dozindave in forum What's Wrong With My Code?
    Replies: 1
    Last Post: November 18th, 2012, 10:31 PM
  4. [SOLVED] stuck on an assignment and need help with repetition
    By teeej86 in forum Loops & Control Statements
    Replies: 1
    Last Post: March 20th, 2011, 07:03 PM
  5. Totally stuck on this assignment
    By Sgiahatch in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 25th, 2010, 04:25 PM