• Post Reply Bookmark Topic Watch Topic
  • New Topic

Need help coding java, sum of squares in a multiplcation table  RSS feed

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Need help with coding java, Write a program that displays the sum of the squares of each integer in the
* multiplication table.
* From Professor:The values in the table should be the rowNum squared plus the
* colNum squared. So, the first entry is 2 (rowNum = 1, colNum = 1. 1^2 + 1^2
* = 1+1 = 2). The next entry is 5 (rowNum = 1, colNum = 2. 1^2 + 2^2 = 1+4 =
* 5).
My code: It does not print anything after the title. Dont know whats missing:-(

 
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, and welcome to the Ranch!

When posting code, please UseCodeTags(←click) so that it will be readable. I've added them to your post for you this time.

As for your problem, contrary to what you state, that code actually prints two things after the title.

1) It prints the toString() representation of the num array, which is garbage for humans. If you want to print the contents of an array, you need to iterate and print the individual elements one by one, or use java.util.Arrays.toString(). I'd recommend you take the first route for now, for practice.

2) It prints sum, which is 0. Why do you think sum is 0? If you can't figure it out after studying your code for a few minutes, then add a couple more println() calls inside the loop to print out the various intermediate values.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!