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
- برمجة جافا
- 2022-04-19
- softwareEngineer
الأجوبة
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]+" ");
}
}
}
أسئلة مشابهة
القوائم الدراسية التي ينتمي لها السؤال