id/email
password
forgot password | create account
about | help | code help+videos | done | prefs
CodingBat code practice

 

simona1@sfusd.edu two_d_arrays > sumOfSquares
prev  |  next  |  chance

Write a method named sumOfSquares that returns a string representation of a two-dimensional array of int. The parameter is the number of rows (the number of columns is the same.) This square matrix should have each element be the sum of the squares of the row number and the column number. For example, sumOfSquares(3) should return {{0,1,4},{1,2,5},{4,5,8}}. It may help to write this as a square matrix to see the calculation more clearly. Create the array in this method, then use toString() to return the array as a string. You must cut and paste method toString() from the Hint.


sumOfSquares(1) → "{{0}}"
sumOfSquares(2) → "{{0,1},{1,2}}"
sumOfSquares(3) → "{{0,1,4},{1,2,5},{4,5,8}}"

...Save, Compile, Run (ctrl-enter)

public String sumOfSquares(int a) { }

Editor font size %:
Shorter output


Forget It! -- delete my code for this problem

Progress graphs:
 Your progress graph for this problem
 Random user progress graph for this problem
 Random Epic Progress Graph

Java Help

Misc Code Practice

Difficulty: 325 Post-solution available

Copyright Nick Parlante 2017 - privacy