Results 1 to 2 of 2

Thread: Addition Table?

  1. #1
    zhider is offline Member
    Join Date
    Oct 2012
    Posts
    37
    Rep Power
    0

    Default Addition Table?

    This is the code for an addition table I made for my class. This prints the table properly, but the teacher said "Your printAdditionTable is printing the whole table itself instead of using a method to do a row and then repeating that method (that row) with a different starting value." I think I need to do a loop, but dont know how would I do this. any help would be appreciated.


    Java Code:
    public static void printAddTable (){
         int i = 0, j=0;
         for (i=0; i<=12; i++) {
         for (j=0; j<=12; j++){   
              System.out.print (i+j+ "   ");
         }
         System.out.println ("   ");
         }
    }

  2. #2
    SJF
    SJF is offline Senior Member
    Join Date
    Oct 2012
    Posts
    108
    Rep Power
    0

    Default Re: Addition Table?

    Java Code:
    public static void printRow(int i, int max){
        for(int j = 0; j<=max; j++){
            System.out.print(i + j + "\t"); /Print entry plus tab char.
        }
        System.out.println();
    }
    Something like this for printing a row at a time. You've got the right idea to begin with, just need to create a method to do it.

Similar Threads

  1. Need help with Addition Calculator!
    By Laon8orsSon in forum New To Java
    Replies: 4
    Last Post: 05-24-2012, 11:27 AM
  2. addition
    By rithish in forum New To Java
    Replies: 4
    Last Post: 10-04-2011, 08:15 AM
  3. Addition of Two time
    By jithan in forum New To Java
    Replies: 5
    Last Post: 12-29-2008, 11:09 AM
  4. Addition Problem
    By tornado in forum New To Java
    Replies: 6
    Last Post: 12-06-2008, 11:37 PM
  5. string addition??
    By j2vdk in forum New To Java
    Replies: 2
    Last Post: 09-03-2008, 03:41 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •