aspose file tools*
The moose likes Beginning Java and the fly likes Multiplication Table Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Multiplication Table" Watch "Multiplication Table" New topic
Author

Multiplication Table

Austin Smith
Greenhorn

Joined: Sep 26, 2011
Posts: 4
Hello. I am currently working on making a multiplication table where you enter in your own dimensions. I managed to get the prompt to work, but whenever I enter in my own numbers I am unable to get my desired result. Also, I'm slightly new to Java. Here is what code I have so far:

fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11401
    
  16

zeroeth...Welcome to the Ranch! Hopefully we'll be able to help you. to that point...

First, we have no idea what your 'desired result' is, so it would help if you clarify.

Second, since you know what this DOES do, it would help if you told us. does it compile? Does not start? does it start to run and die? Does is run and give the wrong output? what would that output be?

third, you should never get this far. NEVER write more than 2-3 lines of code before you compile and test. Do you know if your input is being processed correctly? Do you know if your loops are running the correct number of times? etc.

fourth...the best way to see what's going on is to stick a ton of System.out.println statements in there to see where it is going.

fifth...this is wrong:


There is something in there that is causing your loop to not do what you think it is...it is running, but it is not doing anything terribly useful.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11401
    
  16

sixth...
this has at least two errors:

one error is the same as the other loop. this is the entire loop statement due to your error. what you think is the body of the loop actually isn't.

also, you set maxcol to 1, test to see if it is less than col. You then increment col. so, if maxcol is less than col, it will be less than col +1, +2, +3, etc., until col rolls over the integer max and becomes the integer minimum, and negative.
Austin Smith
Greenhorn

Joined: Sep 26, 2011
Posts: 4
Sorry about the late reply.

The desired output should look something like this:

1 2 3 4 5 6 7 8 9 10

1 1 2 3 4 5 6 7 8 9 10
2 2 4 6 8 10 12 14 16 18 20
3 3 6 9 12 15 18 21 24 27 30
4 4 8 12 16 20 24 28 32 36 40
5 5 10 15 20 25 30 35 40 45 50
6 6 12 18 24 30 36 42 48 54 60
7 7 14 21 28 35 42 49 56 63 70
8 8 16 24 32 40 48 56 64 72 80
9 9 18 27 36 45 54 63 72 81 90
10 10 20 30 40 50 60 70 80 90 100


And yes it does compile correctly and when it runs it gives me this(when attempting to get a 10x10 table:

enter row10
enter column10
110 1111



Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14266
    
  21

Pay close attention to Fred's fifth and sixth points, there's a hint there that is most likely the cause of why it doesn't work like you think it should. Especially this:
fred rosenberger wrote:what you think is the body of the loop actually isn't.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Austin Smith
Greenhorn

Joined: Sep 26, 2011
Posts: 4
Ok thanks. I figured out my problem so I redid it after my prompt.


But now when I compile it, it says
C:\Users\Smit6863\Desktop\Multiplication.java:13: illegal character: \96
`
^
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11401
    
  16

so, look at your line 13 and see if there is a character there that perhaps ought not be there.

Heck...the error message even shows you what it is.
Austin Smith
Greenhorn

Joined: Sep 26, 2011
Posts: 4
Oh...oops. Thanks for the help everyone!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Multiplication Table