class CicularShiftn
{
public static void main(String[] args)
{
int a[]=new int[10];
int temp,n,i,j,b=2;
Console con=System.console();
System.out.println("Enter the 10 elements in array : ");
for(i=0;i<10;i++)
{
int no=(int)(Math.random()*100);
a[i]=no;
}
System.out.println("Array elements are : ");
for(int value:a)
System.out.println(value);
System.out.println("Enter the position from which you want to shift : ");
n=Integer.parseInt(con.readLine());
i=0; j=n;
while(i<j)
{
temp=a[i];
for(i=0;i<9;i++)
a[i]=a[i+1];
a[i]=temp;
i=0;
j--;
}
System.out.println("Now array elements are ");
for(int value1:a)
System.out.println(value1);
}
}
{
public static void main(String[] args)
{
int a[]=new int[10];
int temp,n,i,j,b=2;
Console con=System.console();
System.out.println("Enter the 10 elements in array : ");
for(i=0;i<10;i++)
{
int no=(int)(Math.random()*100);
a[i]=no;
}
System.out.println("Array elements are : ");
for(int value:a)
System.out.println(value);
System.out.println("Enter the position from which you want to shift : ");
n=Integer.parseInt(con.readLine());
i=0; j=n;
while(i<j)
{
temp=a[i];
for(i=0;i<9;i++)
a[i]=a[i+1];
a[i]=temp;
i=0;
j--;
}
System.out.println("Now array elements are ");
for(int value1:a)
System.out.println(value1);
}
}
No comments:
Post a Comment