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

Thread: how do I get this output?

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

    Default how do I get this output?

     0 1 2 3 4 5 6 7 8 9 10 11 
    1 2 3 4 5 6 7 8 9 10 11 12
    2 3 4 5 6 7 8 9 10 11 12
    etc.
    This is what I have so far
     public static void printAdditionTable () {  
           for (int rows=0; rows<=11; rows++){
            printRow (rows);
                }	
          }
          public static void printRow(int i) {
              for(int num=i;num<12; num++)
                {
                     System.out.print(num +" ");
                }
     
                System.out.println();
                 }
    I do not know how to get my first row to only have 0-11 and not 0-12


  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: how do I get this output?

    Can you post what the code currently outputs
    and also what you want the code to output.
    If you don't understand my answer, don't ignore it, ask a question.

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

    Default Re: how do I get this output?

    Currently outputs:
    [code=Java]
    0 1 2 3 4 5 6 7 8 9 10 11
    1 2 3 4 5 6 7 8 9 10 11
    2 3 4 5 6 7 8 9 10 11
    3 4 5 6 7 8 9 10 11
    4 5 6 7 8 9 10 11
    5 6 7 8 9 10 11
    6 7 8 9 10 11
    7 8 9 10 11
    8 9 10 11
    9 10 11
    10 11
    11 [code]

    I want this
    0 1 2 3 4 5 6 7 8 9 10 11
    1 2 3 4 5 6 7 8 9 10 11 12
    2 3 4 5 6 7 8 9 10 11 12 
    3 4 5 6 7 8 9 10 11 12
    4 5 6 7 8 9 10 11 12
    etc.

  4. #4
    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: how do I get this output?

    Is this what you want?

    The first line prints 12 numbers
    The second line prints some numbers, the last number is 12
    the third line prints some numbers , the last number is 12
    the next line prints some numbers, the last number is 12

    Looks like the printing should stop for two cases. Can you see them?
    If you don't understand my answer, don't ignore it, ask a question.

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

    Default Re: how do I get this output?

    yeah, and no
    Wait, I might have it
    public static void printAdditionTable () {  
           for (int rows=0; rows<=11; rows++){
            printRow (rows);
                }	
          }
          public static void printRow(int i) {
              for(int num=i;num<=12; num++)
                {
                     System.out.print(num +" ");
                }
     
                System.out.println();
                 }

Similar Threads

  1. how could I output to a text area the output of a method
    By mia_tech in forum What's Wrong With My Code?
    Replies: 6
    Last Post: July 12th, 2012, 07:49 PM
  2. output did not appear
    By iswan in forum AWT / Java Swing
    Replies: 1
    Last Post: October 27th, 2011, 06:33 AM
  3. What would be the output of this?
    By colerelm in forum Java Theory & Questions
    Replies: 2
    Last Post: October 24th, 2011, 03:51 PM
  4. what's the output?
    By dcshoecousa in forum Java Theory & Questions
    Replies: 3
    Last Post: November 27th, 2010, 11:11 AM
  5. Why am I getting this output?
    By ptabatt in forum What's Wrong With My Code?
    Replies: 5
    Last Post: August 6th, 2010, 07:36 PM