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

Thread: Addition Table.

  1. #1
    Member
    Join Date
    Sep 2012
    Posts
    98
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Addition Table.

    Thanks kevin for help on the last post, it really helped a lot, but I am now trying to make an addition table with a logarithm at the top, which works. The addition table is actually a multiplication table but I need to convert it to an addition table, i've tried tinkering with some variables but I cannot seem to do it, thanks!
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    package mathtables;
     
    /**
     *
     * @author student
     */
    public class MathTables {
     
     
        public static void main(String[] args) {
     
     
            printCommonLogTable();
            printAdditionTable ();
     
        }
     
        public static void printCommonLogTable () {
            double x = .5;
            while (x < 10.0) {
                System.out.println(x + "  " + Math.log(x));
                x = x + .5;
            }
     
     
        }
        public static void printAdditionTable () {
            {
             int i = 1;
             while (i <= 12) {
                 printMultiples (i);
                 i = i + 1;
             }
     
            }
            System.out.println("");
     
     
        }
        public static void printMultiples (int n) {
            int i = 1;
            while (i <= 12) {
                System.out.print(n*i + "   ");
                i = i + 1;
            }
            System.out.println("");
        }
     
    }


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Addition Table.

    What exactly do you mean when you say you cannot seem to do it? What does it do instead? Have you tried stepping through this with a debugger, or at least a piece of paper and a pencil?
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Member
    Join Date
    Sep 2012
    Posts
    98
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Addition Table.

    It runs fine, but I am trying to get it to print a addition table not a multiplication table.
    run:
    0.5  -0.6931471805599453
    1.0  0.0
    1.5  0.4054651081081644
    2.0  0.6931471805599453
    2.5  0.9162907318741551
    3.0  1.0986122886681098
    3.5  1.252762968495368
    4.0  1.3862943611198906
    4.5  1.5040773967762742
    5.0  1.6094379124341003
    5.5  1.7047480922384253
    6.0  1.791759469228055
    6.5  1.8718021769015913
    7.0  1.9459101490553132
    7.5  2.0149030205422647
    8.0  2.0794415416798357
    8.5  2.1400661634962708
    9.0  2.1972245773362196
    9.5  2.2512917986064953
    1   2   3   4   5   6   7   8   9   10   11   12   
    2   4   6   8   10   12   14   16   18   20   22   24   
    3   6   9   12   15   18   21   24   27   30   33   36   
    4   8   12   16   20   24   28   32   36   40   44   48   
    5   10   15   20   25   30   35   40   45   50   55   60   
    6   12   18   24   30   36   42   48   54   60   66   72   
    7   14   21   28   35   42   49   56   63   70   77   84   
    8   16   24   32   40   48   56   64   72   80   88   96   
    9   18   27   36   45   54   63   72   81   90   99   108   
    10   20   30   40   50   60   70   80   90   100   110   120   
    11   22   33   44   55   66   77   88   99   110   121   132   
    12   24   36   48   60   72   84   96   108   120   132   144

  4. #4
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Addition Table.

    Well, you call a function that prints out the multiples, and it does exactly that. What did you expect to happen? Where is the code that's supposed to print out the addition table?
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  5. #5
    Member
    Join Date
    Sep 2012
    Posts
    98
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Addition Table.

    Our teacher gave us the printMultiples example in the book, and told us to copy it and transform it into an addition table. I do not know how to do this and I am looking for some help.

  6. #6
    Member
    Join Date
    Sep 2012
    Posts
    98
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Addition Table.

    Any help would be great.

  7. #7
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Addition Table.

    Think about how you figure out a multiplication table, just with a piece of paper and a pencil. Then look at how the code does the same thing. Now think about how you would figure out an addition table, just with a piece of paper and a pencil. Maybe draw a few until you see a pattern. Then look at the existing code and think about how you would change it to do what you do in your head.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  8. #8
    Member
    Join Date
    Sep 2012
    Posts
    98
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Addition Table.

    Thanks Kevin!

Similar Threads

  1. simple addition inside { of after the if
    By spongyballs in forum Loops & Control Statements
    Replies: 2
    Last Post: October 23rd, 2011, 06:42 PM
  2. [SOLVED] Addition Quiz
    By javaneedhelp in forum Loops & Control Statements
    Replies: 5
    Last Post: October 9th, 2011, 12:55 AM
  3. Addition
    By ruffu054 in forum What's Wrong With My Code?
    Replies: 17
    Last Post: August 14th, 2011, 10:49 PM
  4. text value addition problem
    By kundan_101 in forum JavaServer Pages: JSP & JSTL
    Replies: 1
    Last Post: January 8th, 2011, 11:46 AM