-
Program to find largest of N numbers in an array
almost 9 years ago
-
almost 7 years ago
Well here's the example,
import java.util.Scanner; public class MaxValue { public static void main(String[] args) { int num, maxValue; Scanner sc = new Scanner(System.in); System.out.print("Please enter number of elements in the array : "); num = sc.nextInt(); int arr[] = new int[num]; System.out.println("Please enter elements of array : "); for(int a = 0; a < num; a++) { arr[a] = sc.nextInt(); } maxValue = arr[0]; for(int a = 0; a < num; a++) { if(maxValue < arr[a]) { maxValue = arr[a]; } } System.out.println("Max of array in java : " + maxValue); sc.close(); } } You can find more here in this link, http://www.flowerbrackets.com/java-program-to-find-largest-and-smallest-number-in-an-array/
-
1 Comment(s)