diff --git a/Find the largest and smallest number b/Find the largest and smallest number index 3626310..3a8f632 100644 --- a/Find the largest and smallest number +++ b/Find the largest and smallest number @@ -1,17 +1,19 @@ /* Program to find the largest and smallest number in an array */ - -#include -int main() +import java.util.*; +public class Xyz { - int i, arr[10] = {2, 5, 4, 1, 8, 9, 10, 6, 3, 7}; - long int small, large; - small = large = arr[0]; - for(i=1; i<10; i++) - { - if(arr[i] < small) - small = arr[i]; - if(arr[i] > large) - large = arr[i]; - } - printf("Smallest = %d, Largest = %d\n", small, large); +public static void main (String args[]) +{ +int [] arr={1,3,6,8,7,-6,-8,0,3}; +System.out.println("Smalest And Largest Number Are"); +System.out.println(Arrays.toStrings(lagest&smallest(arr))); +} +public static int[] lagest&smallest(int arr[]) +{ + Arrays.sort(arr); + int arr1[]= new int[2]; + arr1[0]=arr[0]; + arr1[1]=arr[arr.length-1]; + return arr1; +} }