Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Multiplication Table

 
Austin Smith
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12185
34
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12185
34
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 15438
41
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Austin Smith
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12185
34
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh...oops. Thanks for the help everyone!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic