Computer Science, asked by vijetas447, 3 months ago


Write a program to return the difference between the largest and smallest numbers from an
array of positive integers
Note
You are expected to write code in the findLarge SmallDifference function only which will
receive the first parameter as the number of items in the array and second parameter as the
array itself. You are not required to take input from the console
Example
Finding the difference between the largest and smallest from a list of 5 numbers
Input
input1: 5
input2: 10 11 7 12 14
Output
Explanation
The first parameter (5) is the size of the array. Next is an array of integers. The difference
between the largest (14) and the smallest (7) numbers is 7​

Answers

Answered by SikhaSardar
42

Answer:

The first parameter (5) is the size of the array. Next is an array of integers. The difference

between the largest (14) and the smallest (7) numbers is 7

Answered by amanpanday2811
0

Answer:

The first parameter (5) is the size of the array. Next is an array of integers. The difference between the largest (14) and the smallest (7) numbers is 7

Explanation:

Array-Java array is an object which contains elements of a similar data type. Additionally, The elements of an array are stored in a contiguous memory location. It is a data structure where we store similar elements. We can store only a fixed set of elements in a Java array. Array in Java is index-based, the first element of the array is stored at the 0th index, 2nd element is stored on 1st index and so on. Unlike C/C++, we can get the length of the array using the length member. In C/C++, we need to use the size of operator.

Code-

import java.util.Arrays;

public class Exercise28 {

public static void main(String[  args)

{

   int[ array_nums = {5, 7, 2, 4, 9};

System.out.println("Original Array: "+Arrays.toString(array_nums));

int max_val = array_nums[0];

int min = array_nums[0];

for(int i = 1; i < array_nums.length; i++)

{

 if(array_nums[i] > max_val)

  max_val = array_nums[i];

 else if(array_nums[i] < min)

  min = array_nums[i];

}

System.out.println("Difference between the largest and smallest values of the said array: "+(max_val-min));

}

For more refers to-

https://brainly.in/question/4234614?referrer=searchResults

https://brainly.in/question/9763781?referrer=searchResults

#SPJ3

Similar questions