Array

11. Program

(Imp_Q) How to find out max value from an int array ?

class R { public static void main(String args[]) { int[] a = {10, 2, 5, 3, 9, 2, 8, 10, 11, 20, 10}; int max = a[0]; for(int i = 1; i < a.length ; i++) { if(a[i] > max) { max = a[i]; } } System.out.println("Maximum value of array is : "+max); } }

12. Program

(Imp_Q) How to find out min value from an int array ?

class S { public static void main(String args[]) { int[] a = {10, 2, 5, 3, 9, 2, 8, 10, 11, 20, 10}; int min = a[0]; for(int i = 1; i < a.length ; i++) { if(a[i] < min) { min = a[i]; } } System.out.println("Minimum value of array is : "+ min); } }

13. Program

How to find out sum of element of an int array ?

class T { public static void main(String args[]) { int[] a = {10, 2, 5, 3, 9, 2, 8, 10, 11, 20, 10}; int sum = 0; for(int i = 0; i < a.length; i++) { sum = sum + a[i]; } System.out.println("Sum of element is : "+ sum); } }

Page....