Write a program to find the maximum element in a array?

This Java Example shows how to find maximum number in an array.


								
/**
 * @author Mindclues
 */

public class MaxElement {
	public static void main(String args[]) {
		
		int ary[] = { 2, 4, 2, 1, 23, 3, 21 };		
		int a = ary[0];
		
		for (int i = 0; i < ary.length; i++) {
			if (a < ary[i]) {
				a = ary[i];
			}
		}
		
		System.out.println("Max element in array :- " + a);
	}

}
							

								
Max element in array :- 23
							

Related Articles

post a comment