Page 308 - computer science (868) class 11
P. 308

13              {
                14                  System.out.print ("enter a number: ");

                15                  arr[i] = sc.nextInt();
                16              }

                17              temp=arr[n-1];
                18              for(i=n-1; i>0; i--)

                19              {
                20                  arr[i]=arr[i-1];
                21              }

                22              arr[0]=temp;

                23              for(i = 0; i<n; i++)
                24              {
                25                  System.out.print(arr[i]+" ");

                26              }
                27          }

                28      }

              The output of the preceding program is as follows:
              Enter the size of the array:
              3
              Enter a number: 15
              Enter a number: 63
              Enter a number: 40
              40 15 63


                Program 9      Write a program in Java to create an array of size 3 × 3 and arrange the elements in the array
                               is ascending order.

                1       import java.util.*;

                2       class dda_ascending
                3       {

                4           public static void main()
                5           {

                6               int i, j, k, t;
                7               int a[ ][ ]=new int[3][3];

                8               Scanner sc= new Scanner(System.in);
                9               for(i=0; i<3; i++)





                306306  Touchpad Computer Science-XI
   303   304   305   306   307   308   309   310   311   312   313