Monday, 28 March 2016

Circular Shift in Java

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);
}
}

No comments:

Post a Comment

Read contacts in iOS using Swift with error handling

Just copy and paste the below code Pre-step before pasting the below code Add below line in AppDelegate.swift file below import statement ...