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

 

jebbert@volusia.k12.fl.us > quiz2021_10_21_SLHL_shift
prev  |  next  |  chance

Write a method that returns a new copy of an array, but with each element shifted left or right by 'howFar' locations in the array. The whole array will either be shifted left by 'howFar' if 'left' is true, but otherwise will be shifted right. As preconditions you may assume that 'howFar' will be a positive number less than the length of the array. Since 'howFar' must be positive and smaller than the length of the array, that makes the smallest allowed value of 'howFar' ONE. Since the array must be longer than that, the smallest allowed array has length TWO. You may not use ArrayList or any other preexisting object-oriented data structures. Look at the test data for examples.


quiz2021_10_21_SLHL_shift([17, 326, 457, 1235, 1235, 568, 235, 348, 152, 45], 4, false) → [235, 348, 152, 45, 17, 326, 457, 1235, 1235, 568]
quiz2021_10_21_SLHL_shift([1, 4, 18, 24, 534, 9348, 91241, 98535], 3, true) → [24, 534, 9348, 91241, 98535, 1, 4, 18]
quiz2021_10_21_SLHL_shift([142, 55, 346, 241, 124, 756], 2, true) → [346, 241, 124, 756, 142, 55]

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

public int[] quiz2021_10_21_SLHL_shift(int[] nums, int howFar, boolean left) { }

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: 250

Copyright Nick Parlante 2017 - privacy