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

Thread: Help make addition table from stopping once it reaches 12

  1. #1
    Member
    Join Date
    Mar 2013
    Posts
    35
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Help make addition table from stopping once it reaches 12

    This is what I'm trying to do:Write a static void method called printAdditionTable that prints a two dimensional addition table for the numbers 0 to 12. Use a helper method that takes an integer parameter and prints one row of the table to demonstrate your knowledge of encapsulation. Use for loops in your methods.


          public static void printAdditionTable (int i) {
     
    	int tablenum = i;
            int rows;
     
    	for (rows = 0; rows<=12; ++rows) {
                    int columns;
     
    		for (columns = 0; columns<=12; columns++) {
     
    			System.out.print  (tablenum + " ");  
     			tablenum+=1;
     
    			if (columns==12) {
    				tablenum = rows;
    				System.out.println();
     			} 
    		}
     
    	} 
    }

    The problems are that the first row is repeated and the numbers do not stop at 12 for the rest of the rows.
    0 1 2 3 4 5 6 7 8 9 10 11 12
    0 1 2 3 4 5 6 7 8 9 10 11 12
    1 2 3 4 5 6 7 8 9 10 11 12 13
    2 3 4 5 6 7 8 9 10 11 12 13 14
    3 4 5 6 7 8 9 10 11 12 13 14 15
    4 5 6 7 8 9 10 11 12 13 14 15 16
    5 6 7 8 9 10 11 12 13 14 15 16 17
    6 7 8 9 10 11 12 13 14 15 16 17 18
    7 8 9 10 11 12 13 14 15 16 17 18 19
    8 9 10 11 12 13 14 15 16 17 18 19 20
    9 10 11 12 13 14 15 16 17 18 19 20 21
    10 11 12 13 14 15 16 17 18 19 20 21 22
    11 12 13 14 15 16 17 18 19 20 21 22 23


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

    Default Re: Help make addition table from stopping once it reaches 12

    the numbers do not stop at 12
    Where are there statements in the code to stop the numbers at 12?


    what value is passed to the method as its arg?


    What do you want the code to print out?
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Addition Table.
    By LoganC in forum What's Wrong With My Code?
    Replies: 7
    Last Post: October 4th, 2012, 12:02 PM
  2. Stopping the entries in a JFrame
    By georger55 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: May 5th, 2012, 09:34 PM
  3. [SOLVED] Stopping java in terminal
    By Scotty in forum Java Theory & Questions
    Replies: 1
    Last Post: May 7th, 2011, 06:53 PM
  4. Stopping Graphics Animation.
    By SyntheticD in forum What's Wrong With My Code?
    Replies: 3
    Last Post: February 25th, 2011, 11:59 AM
  5. While loop stopping?
    By Echo in forum What's Wrong With My Code?
    Replies: 2
    Last Post: October 16th, 2010, 05:40 PM