Write a Program to Find Largest and Smallest Number in Array using Java Programming.

//Largest_Smallest_Number
public class Largest_Smallest_Number {
	public static void main(String args[]) {
		int arrNumber[] = new int[] { 8, 9, 1, 6, 10, 0, 7, 3, 2, 4 };
		int max = arrNumber[0];
		int min = arrNumber[0];
		for (int indexNumber = 1; indexNumber < arrNumber.length; indexNumber++) {
			if (arrNumber[indexNumber] > max) {
				max = arrNumber[indexNumber];
			}
			if (arrNumber[indexNumber] < min) {
				min = arrNumber[indexNumber];
			}

		}
		System.out.println("Largest Number in array is: " + max);
		System.out.println("Smallest Number in Array is: " + min);
	}

}

Output:
Largest_Smallest_Number

(Visited 61 times, 1 visits today)
Share with Friends :
Written by: