diff --git a/array.txt b/array.txt new file mode 100644 index 0000000..5195f86 --- /dev/null +++ b/array.txt @@ -0,0 +1,50 @@ +import java.util.*; +class array{ + int[] a=new int[50]; + int k,s,i; + Scanner sc=new Scanner(System.in); + public void input(){ + System.out.println("Enter the number of elements you want to in an array:"); + s=sc.nextInt(); + System.out.println("Enter the element:"); + for(int i=0;i<=s-1;i++){ + + a[i]=sc.nextInt(); + + } + System.out.println("Enter the position you want want to rotate:"); + k=sc.nextInt(); + rotatearray(); + print(); + + } + public void rotatearray() { + reverseArray(0, k-1); + reverseArray(k, s-1); + reverseArray(0,s-1); + + } + + public void reverseArray(int start, int end) { + while (start < end) { + int temp = a[start]; + a[start] = a[end]; + a[end] = temp; + start++; + end--; + } + } + + public void print(){ + for(int i=0;i<=s-1;i++){ + System.out.print(a[i]+" "); + } + } +} +public class Main{ + public static void main(String[] args){ + array m=new array(); + m.input(); + } +} +