Page 313 - Computer science 868 Class 12
P. 313
32
65
82
56
90
32 65 82 56 90
Enter the number by which the 32 65 82 56 90
Enter the number by which the array elements are to be rotated
22
The contents of the array after rotation are
56 90 32 65 82
Program 2 Write a program to find the largest of two numbers in a given array of size n.
1 import java.util.*;
2 class find_first_second_large
3 {
4 public static void main (String[] args)
5 {
6 Scanner sc = new Scanner (System.in);
7 int size,i,large1, large2, t;
8 System.out.print("Enter no. of elements you want in array:");
9 size = sc.nextInt();
10 int arr[] = new int[size];
11 System.out.println("Enter all the elements:");
12 for (i = 0; i < arr.length; i++)
13 {
14 arr[i] = sc.nextInt();
15 }
16 large1 = arr[0];
17 large2 = arr[1];
18 if (large1 < large2)
19 {
20 t = large1;
21 large1 = large2;
22 large2 = t;
311
Arrays 311

