Page 312 - Computer science 868 Class 12
P. 312

18           // main function to read the array and display the output
                19           public static void main(String[] args)

                20           {
                21               Scanner sc = new Scanner(System.in);

                22               int size,ele_r;
                23               System.out.println("Enter the size of the array");

                24               size = sc.nextInt();
                25               int[] ar_m = new int[size];
                26               System.out.println("Enter array elements");

                27               int i;

                28               for (i = 0; i < ar_m.length; i++)
                29               {
                30                   ar_m[i]=sc.nextInt();

                31               }
                32               System.out.println("The contents of the array before rotation are");

                33               for(i=0;i<ar_m.length;i++)
                34               {

                35                   System.out.print(ar_m[i] + " ");
                36               }

                37               System.out.println();

                38                System.out.println("Enter the number by which the array elements are to
                                  be rotated");
                39               ele_r=sc.nextInt();
                40               rotate(ar_m,ele_r);
                41               System.out.println("The contents of the array after rotation are");

                42               for(i=0;i<ar_m.length;i++)

                43               {
                44                   System.out.print(ar_m[i] + " ");
                45               }

                46           }
                47       }

              Output of the preceding program is as follows:
              Enter the size of the array

              5
              Enter array elements




                310310  Touchpad Computer Science-XII
   307   308   309   310   311   312   313   314   315   316   317