How to Sort 3 Integers in Java
- 1). Create a new file in your Java development program.
- 2). Type the following at the top of the file in your text editor:
import java.util.Arrays;
Java.util.Arrays contains a method that will be used to sort an array of integers. - 3). Create an array of three integers, as in the following example:
int[] array = new int[] {3, 1, 2}; - 4). Sort the array using the Arrays.sort method by typing the following:
Arrays.sort(array);
The Array.sort method sorts the integers in the array by ascending order.