• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic