java code to right rotate an array

Solutions on MaxInterview for java code to right rotate an array by the best coders in the world

showing results for - "java code to right rotate an array"
Lucas
11 Apr 2018
1import java.util.*;
2import java.lang.*;
3import java.io.*;
4
5/* Name of the class has to be "Main" only if the class is public. */
6class Codechef
7{
8	public static void main (String[] args) 
9	{
10	    Scanner sc=new Scanner(System.in);
11		// your code goes here
12		int arr[]= new int[10];
13		arr[0]=5;
14		arr[1]=34;
15		arr[2]=23;
16		arr[3]=6;
17		arr[4]=84;
18		for(int i=0;i<arr.length;i++)
19		{
20		    System.out.print(arr[i]+" ");
21		    
22		}
23		System.out.println("");
24		for(int i=5;i>=2;i--)
25		{
26		    arr[i+1]=arr[i];
27		}
28		arr[2]=15;
29		for(int i=0;i<arr.length;i++)
30		{
31		    System.out.print(arr[i]+" ");
32		   
33		}
34	}
35}
36