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

 

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

Write a method named box 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 all the elements 0 except the outside elements, which should be 1's. For example, box(4) should return {{1,1,1,1},{1,0,0,1},{1,0,0,1},{1,1,1,1}}. 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.


box(1) → "{{1}}"
box(2) → "{{1,1},{1,1}}"
box(3) → "{{1,1,1},{1,0,1},{1,1,1}}"

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

public String box(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: 328 Post-solution available

Copyright Nick Parlante 2017 - privacy