Advertisement
informaticage

Array shifting

Dec 5th, 2019
296
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.40 KB | None | 0 0
  1. public class Program {
  2.  
  3.     public static int[] rototto ( int [] arr, int k ) {
  4.         int [] arr_r = new int [ arr.length ];
  5.         for ( int i = 0; i < arr.length; i++ )
  6.             arr_r [ i ] = arr [ (i + k) % arr.length ];
  7.         return arr_r;
  8.     }
  9.    
  10.     public static void main(String[] args) {
  11.         int [] arr = { 1,2,3,4,5,6,7,8 };
  12.        
  13.         arr = rototto ( arr, 3 );
  14.         for ( int x:arr ) {
  15.             System.out.print(x + " ");
  16.         }
  17.     }
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement