Page 373 - ComputerScience_Class_11
P. 373

33                  System.out.print(oddNumbers[i] + " ");
                  34              }

                  35          }
                  36      }

                 The output of the preceding program is as follows:
                         BlueJ: Terminal Window - Java

                     Options
                    Enter 10 numbers:
                    1
                    2
                    3
                    4
                    5
                    6

                    7
                    8
                    9
                    10
                    Even Numbers: 2 4 6 8 10
                    Odd Numbers: 1 3 5 7 9





                   Program 8     Write a Java program to input n numbers into an array, shift all the elements one position to
                                 the right and move the last element to the first position. Display the updated array after the
                                 shift operation.

                   1      import java.util.*;
                   2      class ArrayShift

                   3      {
                   4          public static void main(String args[])

                   5          {
                   6              Scanner sc= new Scanner(System.in);
                   7              int n;

                   8              System.out.println("Enter size of array:");

                   9              n=sc.nextInt();
                  10              int arr[  ] = new int[n];
                  11              int i, temp;

                  12              for(i = 0; i<n; i++)





                                                                                                           Arrays  371
   368   369   370   371   372   373   374   375   376   377   378