Q:

Write and test a Java method clshift() that takes array of integers and performs a circular left shift on the array, and then prints its elements

1

Exercise 3: Write and test a Java method clshift() that takes array of integers and performs a circular left shift on the array, and then prints its elements.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

public class Main
{
	public static void main(String[] args) {
	    int a[]={3,5,1,2,45};

	  clshift(a);      
	    }
	
	public static void clshift(int []a)
	{
	   /* shifting array elements */
     int temp=a[0];
     for(int i=0;i<a.length-1;i++)
     {
       a[i]=a[i+1];
     }
     a[a.length-1]=temp;
 
     System.out.println("\nNew array after rotating by one postion in the left direction");
     for(int i=0;i<a.length;i++)
     {
       System.out.print(a[i]+" ");
     }

	}
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now