Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- import java.util.Scanner;
- public class task7 {
- /**
- * @param args the command line arguments
- */
- public static void prA(int a[]){
- for(int i=0; i<a.length; i++)
- System.out.print(a[i]+" ");
- }
- public static int[] shiftRight(int array[], int k) {
- System.out.println("the array has been shifted "+ k +" times");
- for(int z=0; z<k; z++){
- for (int i = array.length - 1; i > 0; i--){
- array[i] = array[i - 1];
- }
- array[0] = 0;
- }
- System.out.println("The latest shifted array");
- return array;
- }
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- int a[] = {10, 20, 30, 40, 50};
- System.out.println("The source array");
- prA(a);
- System.out.println();
- System.out.println("Enter the K value");
- int k = sc.nextInt();
- a = shiftRight(a, k);
- prA(a);
- // TODO code application logic here
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement