Program to find largest and smallest number in array in java

Write a program to find largest and smallest number in array in java.

package program;

public class LargestAndSmallestNumber {
public static void main(String[] args) {
	int[] intArray = {8,5,2,6,7,1,9,10,4};
	
	int smallestNumber = intArray[0]; 
	int largestNumber  = intArray[0]; 
	
	for (int i = 1; i < intArray.length; i++) {
		
		if (intArray[i] > largestNumber) {
			largestNumber = intArray[i];
		}
		
		if (intArray[i] < smallestNumber) {
			smallestNumber = intArray[i];
		}
	}

	System.out.println("Largest number  is : " +largestNumber + "  "
			+ "Smallest number is : " +smallestNumber);
	
}
}

Output is – Largest number is : 10 Smallest number is : 1