Circular shift program
Circular shiftA class Circular has been signed to print a set of elements in a circular fashion. For example, if input is 1, 2,3,4 output should be:1,2,3,44,1,2,33,4,1,22,3,4,1Class name: CircularShiftData members/ instance variables:list[ ]: store the elementssize: to store the number of elements
Circular shift program
JAVA videos
Circular shift
A class Circular has been signed to print a set of elements in a circular fashion. For example, if input is 1, 2,3,4 output should be:
1,2,3,4
4,1,2,3
3,4,1,2
2,3,4,1
Class name: CircularShift
Data members/ instance variables:
list[ ]: store the elements
size: to store the number of elements
Member functions:
void input(): to input the size and the elements in the array
void Circular_Shift():to shift the elements of the array one place to the right. First element comes to the second position, second element to the third and ultimately the last element comes to the first position and so on.
void reverse(): reverse the array without using any temporary variable to swap its elements.
void display(): to display the array in a circular fashion.
Specify the class CircularShift giving details of the constructor and member
functions void input(), void Circular_Shift(), void reverse(). void display() define the main() function to create an object and call the functions accordingly.
import java.util.Scanner;
class CircularShift
{
static int list[];
static int size;
void input()
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter the number of elements");
size = sc.nextInt();
list = new int[size];
System.out.println("Enter the elements");
for(int i = 0;i<size;i++)
{
list[i] = sc.nextInt();
}
}
void Circular_Shift()
{
int temp=list[size-1];
for(int i=size-1;i>0;i--)
{
list[i]=list[i-1];
}
list[0]=temp;
}
void reverse()
{
for (int i = 0; i < size/2; i++)
{
int temp = list[i];
list[i] = list[size - 1 - i];
list[size - 1 - i] = temp;
}
}
void display()
{
System.out.println("The array is as follows :");
for(int i = 0;i<=size;i++)
{
if(i!=0 && i<size)
{
Circular_Shift();
for(int j = 0;j<size;j++)
{
System.out.print(list[j]+",");
}
System.out.println("");
}
if(i==0)
{
for(int j = 0;j<size;j++)
{
System.out.print(list[j]+",");
}
System.out.println();
}
if(i==(size-1))
{
Circular_Shift();
}
}
}
public static void main()
{
CircularShift obj = new CircularShift();
obj.input();
obj.display();
obj.reverse();
System.out.println("Reversed array :");
for(int i = 0;i<size;i++)
{
System.out.print(list[i]+",");
}
}
}
Circular prime number program
Related Posts
Continue learning with these related articles

ISC Practical 2027: College Enrolment Code Validator and Stream Report – Algorithm and Java Program
Fully solved ISC Computer Science Practical 2027 question: validate college enrolment codes made of a stream, year and serial number, give the exact reason for each rejection, auto-correct lowercase streams and prepare a stream-wise report.

ISC Practical 2027: Digital Lock Security Code Analyzer – Algorithm and Java Program
Fully solved ISC Computer Science Practical 2027 number-logic question: for a 5 to 10 digit security code, find the first and last digits, odd and even position sums, product of non-zero digits, digit frequency and classify the code as STRONG, MODERATE or WEAK.

Boolean Algebra for ISC Class 12: Laws, Canonical SOP and POS, and Simplification
ISC Class 12 Computer Science notes on Boolean algebra: all the laws and theorems, duality, De Morgan's laws, minterms and maxterms, converting to canonical SOP and POS, and step-by-step algebraic simplification with solved examples.