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

Logic Gates for ISC Class 11: Truth Tables, Universal Gates, Half and Full Adder
ISC Class 11 Computer Science notes on logic gates: AND, OR, NOT, NAND, NOR, XOR and XNOR with truth tables, why NAND and NOR are universal gates, and half adder and full adder circuits with their Boolean expressions.
Decimal to Binary Conversion in Java: 3 Programs with Examples
How to convert a decimal number to binary on paper and in Java: three programs (String, place value and Integer.toBinaryString), binary to decimal, a dry run and common mistakes.

ISC Class 11 Computer Science Sample Paper 2026-27 with Solutions
A full 70-mark ISC Class 11 Computer Science sample paper for the 2026-27 annual exam: MCQs, number systems, propositional logic, logic gates, Java classes, arrays, strings, searching and sorting, and computing ethics, with complete worked solutions.