• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Multiplication Table

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:

 
lowercase baba
Posts: 13091
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 13091
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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



 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 13091
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh...oops. Thanks for the help everyone!
 
For my next feat, I will require a volunteer from the audience! Perhaps this tiny ad?
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic