SHARE
TWEET

Untitled

a guest Sep 21st, 2019 73 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6.  
  7. import java.util.Scanner;
  8. public class task7 {
  9.  
  10.     /**
  11.      * @param args the command line arguments
  12.      */
  13.     public static void prA(int a[]){
  14.         for(int i=0; i<a.length; i++)
  15.             System.out.print(a[i]+" ");
  16.     }
  17.        
  18.         public static int[] shiftRight(int array[], int k) {
  19.            System.out.println("the array has been shifted "+ k +" times");
  20.            for(int z=0; z<k; z++){
  21.              for (int i = array.length - 1; i > 0; i--){
  22. array[i] = array[i - 1];
  23.            }
  24. array[0] = 0;
  25.            }
  26.       System.out.println("The latest shifted array");
  27.         return array;    
  28.     }
  29.        
  30.     public static void main(String[] args) {
  31.         Scanner sc = new Scanner(System.in);
  32.         int a[] = {10, 20, 30, 40, 50};
  33.         System.out.println("The source array");
  34.         prA(a);
  35.         System.out.println();
  36.         System.out.println("Enter the K value");
  37.         int k = sc.nextInt();
  38.         a = shiftRight(a, k);
  39.         prA(a);
  40.         // TODO code application logic here
  41.     }
  42.    
  43. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top