Page 331 - Cs_withBlue_J_C11_Flipbook
P. 331
22 else
23 {
24 odd[len2++] = arr[i];
25 }
26 }
27 System.out.print("List of even numbers: ");
28 for(i = 0; i<len1; i++)
29 System.out.print(even[i] + " ");
30 System.out.print("\nList of odd numbers: ");
31 for(i = 0; i<len2; i++)
32 System.out.print(odd[i] + " ");
33 }
34 }
The output of the preceding program is as follows:
Enter a number: 10
Enter a number: 25
Enter a number: 39
Enter a number: 40
Enter a number: 50
List of even numbers: 10 40 50
List of odd numbers: 25 39
Program 8 Input “n” numbers of elements in an array ar[ ]. Shift the numbers into the next cell in a cyclic
order. Then display the elements of the array.
1 import java.util.*;
2 class arr_shift
3 {
4 public static void main()
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++)
329
Arrays 329

