Array is the most important thing in any programming language.
Declaration of an array:
int num[]; or int num = new int[2];
Some times user declares an array and it's size simultaneously. You may or may not be define the size in the declaration time. such as:
int num[] = {50,20,45,82,25,63};
In this program we will see how to declare and implementation. This program illustrates that the array working way. This program takes the numbers present in the num[] array in unordered list and prints numbers in ascending order. In this program the sort() function of the java.util.*; package is using to sort all the numbers present in the num[] array. The Arrays.sort() automatically sorts the list of number in ascending order by default. This function held the argument which is the array name num.
Here is the code of the program:-
import java.util.*;
|
C:\chandan>javac array.java C:\chandan>java array Given number : 50 20 45 82 25 63 Ascending order number : 20 25 45 50 63 82 |
No comments:
Post a Comment