Advertisement
msd_rock

Untitled

May 27th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.62 KB | None | 0 0
  1. public class Test {
  2.  
  3.     public static void main(String[] args) {
  4.         int array[] = { 4, 8, 9, 5, 1 }; // 9 5 1 4 8
  5.  
  6.         Solution1 s = new Solution1();
  7.         s.rotateLeft(array,2);
  8.     }
  9.  
  10. }
  11.  
  12. class Solution1 {
  13.     public int[] rotateLeft(int a[],int x) {
  14.         int a1[] = new int[a.length];
  15.        
  16.         int k = (a.length + 1) - x;
  17.        
  18.         int j=0;
  19.         int temp[] = new int[x-1];
  20.         /*
  21.         for(int r=0; r <=k; r++)
  22.         {
  23.             temp[r]=a[k];
  24.             k--;
  25.            
  26.         }
  27.         */
  28.         for(int i=x ;i<a.length; i++) //i=0 ; 1<4
  29.         {
  30.             a1[j]= a[i];  
  31.             j++;
  32.            
  33.         }
  34.    
  35.         for (int i : a1)
  36.         {
  37.             System.out.print(i + " ");
  38.         }
  39.         return a;
  40.        
  41.    
  42.     }
  43.    
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement