Program to Left rotate the elements of an array using Java

 ROTATE ARRAY TO LEFT BY N POSITION USING JAVA

For a complete tutorial on how to rotate array elements to left by N position.

CHECK OUT BELOW VIDEO👇


DO SUBSCRIBE MY YOUTUBE CHANNEL FOR MORE TUTORIALS.

PROGRAM TO ROTATE ARRAY ELEMENTS TO LEFT BY N POSITION 

SOURCE CODE :

import java.util.Scanner;

public class RotateArrayToLeft

{

public static void main(String[] args)

{

int a[]= {1,2,3,5,6,7,8,9,10};

System.out.println("Input Array : ");

for(int i=0;i<a.length;i++)

{

System.out.print(a[i]+" ");

}

Scanner sc=new Scanner(System.in);

System.out.println("\nEnter how many times you want to rotate array to left : ");

int no=sc.nextInt();

for(int i=0;i<no;i++)

{

    int first=a[0];

   for(int j=0;j<a.length-1;j++)

  {

a[j]=a[j+1];

  }

  a[a.length-1]=first;

}

System.out.println("Output Array : ");

for(int i=0;i<a.length;i++)

{

System.out.print(a[i]+" ");

}

}

}

IMAGE REFERENCED IN THE VIDEO FOR EXPLAINING THE CONCEPTS.



****************IMPORTANT**********  
IF YOU ARE FACING ANY PROBLEM DO CONTACT ME                                                                        

MAIL ME AT @mjmuradali31@gmail.com    

OR

DM ME ON INSTAGRAM at @muradalimj (👈👈CLICK HERE)

OR

DM ME ON FACEBOOK at Murad Ali (👈👈CLICK HERE)

******************************************

THANK YOU:)

CODE WITH MURAD

Post a Comment

0 Comments