Sunday, January 12, 2014

methods to find the highest and lowest integer values in the array.

// Write a getHighest(int[] arr)
// which returns the highest
// integer value in the array.
// And also write a getlowest(int[] arr)
// which returns the lowest
// integer value in the array.
class p429
{ public static int getHighest(int []arr)
  {  int i,m;
     m=arr[0];
     for(i=1;i<arr.length;i++)
        if(m<arr[i]) m=arr[i];
     return m;
  }
  public static int getLowest(int []arr)
  {  int i,m;
     m=arr[0];
     for(i=1;i<arr.length;i++)
        if(m>arr[i]) m=arr[i];
     return m;
  }
  public static void main(String args[])
  {
    int a[]={32,4,12,5,53,10};
    System.out.println("Highest Value = " + getHighest(a));
    System.out.println("Lowest Value = " + getLowest(a));
  }
}

No comments:

Post a Comment