Explanation of Solution
Compute maximum and minimum of an array:
Consider the below java code for a loop that simultaneously computes both the maximum and minimum of an array:
//imagine the first element as minimum number
int min = my_values[0];
//imagine the first element as maximum number
int max = my_values[0];
//loop to compute both maximum and minimum values
for (int i = 1; i < my_values.length; i++)
{
//checks whether my_values[i] is greater than max or not
if (my_values[i] > max)
{
//store the maximum value into max
max = my_values[i];
}
//checks whether my_values is less than min or not
if (my_values[i] < min)
{
//store the minimum value into a min
min = my_values[i];
}
}
//print the maximum number in the given array
System.out.println("maximum Number in a given array is : " + max);
//print the minimum number in the given array
System...
Want to see the full answer?
Check out a sample textbook solutionChapter 6 Solutions
Big Java Late Objects
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education