+ 2
Plz help me in this code to rotate aray by specified number ,not getting expected output
public static void main(String[] args){ Â Â System.out.print("Enter size of array : "); Â Â Scanner input = new Scanner(System.in); Â Â int n=input.nextInt(); Â Â System.out.println("Enter elemnt of array : "); Â Â int arr[] = new int[n+1]; Â Â for(int i=0;i<n;i++){ Â Â Â Â arr[i]=input.nextInt(); Â Â } Â Â int k=input.nextInt(); Â Â int temp=arr[0]; Â Â for(int j=1;j<k;j++){ Â Â Â Â arr[j-1]=arr[j]; Â Â arr[n-1]=temp; Â Â } Â Â Â Â for (int i = 0; i < n; i++) Â Â Â Â Â Â System.out.print(arr[i] + " "); Â Â } }
1 Answer
+ 1
If I got it correctly you want to do something like this: https://code.sololearn.com/cogSyu0oBWpw
I've added a bunch of comments but feel free to ask if you have any further question.