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

 

naturals


Define a function that when passed an integer (say n), returns an array containing the numbers 1, 2, ..., n in that order. Return an empty array if n <= 0.


naturals(0) → []
naturals(-5) → []
naturals(8) → [1, 2, 3, 4, 5, 6, 7, 8]

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

int[] naturals(int n) { }

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: 3 Post-solution available

Copyright Nick Parlante 2017 - privacy