Skip to content

Commit

Permalink
LeftRotate Array
Browse files Browse the repository at this point in the history
Java Code to rotate array to left
  • Loading branch information
gaurav-lomte23 authored Oct 18, 2022
1 parent 4641416 commit 75f5b0a
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions RoatateArray.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import java.io.*;
import java.util.*;
class LeftRotateArray{
public static void main(String args[]){
int n;
Scanner sc=new Scanner(System.in);
System.out.println("Enter the value of N");
n=sc.nextInt();
int arr[]=new int[n];
System.out.println("Enter The Array Elements");
for(int i=0;i<n;i++){
arr[i]=sc.nextInt();
}
System.out.println("The array list before rotation");
for(int j=0;j<n;j++){
System.out.print(arr[j]+"\t");
}
System.out.println("The array list after rotation");
int first=arr[0];
for(int k=0;k<n;k++){
if(k==(n-1)){
arr[n-1]=first;
}
else{
arr[k]=arr[k+1];
}
}
for(int l=0;l<n;l++){
System.out.print(arr[l]+"\t");
}
}
}

0 comments on commit 75f5b0a

Please sign in to comment.