Page 374 - ComputerScience_Class_11
P. 374
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:
BlueJ: Terminal Window - Java
Options
Enter size of an array:
5
Enter a number: 1
Enter a number: 2
Enter a number: 3
Enter a number: 4
Enter a number: 5
5 1 2 3 4
Program 9 Write a Java program to create an array of size 3 × 3 and arrange the elements in the array in
an ascending order.
1 import java.util.Scanner;
2 public class ArraySort
3 {
4 public static void main(String args[])
372 Touchpad Computer Science (Ver. 3.0)-XI

