Question

Write a program that uses an array of integers initialized to whatever values you wish. Write...

Write a program that uses an array of integers initialized to whatever values you wish. Write a methods to calculate and return the minimum and a method to calculate and return the maximum value in the array. Write an additional method that accepts the array as a parameter and then creates and returns a new array with all the same values as the original plus 10. (num +=10)

In Java

Homework Answers

Answer #1

Screenshot of the code:

Sample output:

Code to copy:

//Define the class.

public class arrays

{

//Define the main function.

public static void main(String[] args)

{

//Initialize the value as per your wish.

int arr[] = {1,2,3,4,5,6,7,8,9,10};

  

//Call the function getMinValue and

//store the return value in the

//variable min_value.

int min_value = getMinValue(arr);

//Call the function getMaxValue and

//store the return value in the

//variable max_value.

int max_value = getMaxValue(arr);

//Call the function additional_method and

//store the return array in the

//variable final_array.

int new_array[] = additional_method(arr);

  

//Display the min, max , and the array.

System.out.println("The minimum value is : "+ min_value);

System.out.println("The maximum value is : "+ max_value);

System.out.println("Final values in the array "

+ "after adding 10 is : ");

//Display the new array.

for (int i = 0; i < new_array.length; i++)

{

System.out.print(new_array[i] + " ");

}

  

}

//Define the function to extract

//the maximum value for the array.

public static int getMaxValue(int[] array)

{

//Store the first element of the

//array in the variable x.

int x = array[0];

//Begin the for loop.

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

{

//Compare the elements of

//the array with x.

if (array[i] > x)

{

//Store the minimum value

//of the array in x.

x = array[i];

}

}

//Return the value of x.

return x;

}

//Define the function to extract

//the minimum value for the array.

public static int getMinValue(int[] array)

{

//Store the first element of the

//array in the variable x.

int x = array[0];

//Begin the for loop.

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

{

//Compare the elements of

//the array with x.

if (array[i] < x)

{

//Store the minimum value

//of the array in x.

x = array[i];

}

}

//Return the value of x.

return x;

}

  

//Define the function to compute the new array.

public static int[] additional_method(int num[])

{

//Begin the for loop.

for(int i=0;i<num.length;i++)

{

//Add 10 to each value of the initial

//array , and store the elements

//in the new array num.

num[i] = num[i] + 10;

  

}

  

//Return the new_array to

//the main function.

return num;

}

  

}

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Write a Java program that asks the user to enter an array of integers in the...
Write a Java program that asks the user to enter an array of integers in the main method. The program should prompt the user for the number of elements in the array and then the elements of the array. The program should then call a method named isSorted that accepts an array of and returns true if the list is in sorted (increasing) order and false otherwise. For example, if arrays named arr1 and arr2 store [10, 20, 30, 41,...
Its a c++ task. Write a program that reads 10 integers from the user into an...
Its a c++ task. Write a program that reads 10 integers from the user into an array and uses a function arrayMinimum that accepts an integer array a along with its size arraySize as parameters and returns the smallest array element. The program then outputs the result (the smallest array element).
Write a program to determine the minimum element in an array of ten elements. The program...
Write a program to determine the minimum element in an array of ten elements. The program should have the following: 1. Class Name as ArrayProcessing. The main method should create an array of size 10 2. There should be two methods besides the main method in the class namely inputArray and MinimumElement 3. InputArray method should assign the ten elements in the array. Use scanner to input these elements. The array of 10 numbers in the method "InputArray" should be...
Write a program in Java that creates an array of doubles. The array must have size...
Write a program in Java that creates an array of doubles. The array must have size 1000. Fill this array with random numbers between 0 and 1. Then compute and print the total value of all the elements of the array, the mean, the minimum, and the maximum. Filling the array with random numbers must be done by a method that you define and implement. Computing and printing the statistics must be done by another method, which again you must...
Write a program which: Write a program which uses the following arrays: empID: An array of...
Write a program which: Write a program which uses the following arrays: empID: An array of 7 integers to hold employee identification numbers. The array should be initialized with the following values: 1, 2, 3, 4, 5, 6, 7. Hours: an array of seven integers to hold the number of hours worked by each employee. payRate: an array of seven doubles to hold each employee’s hourly pay rate. Wages: an array of seven doubles to hold each employee’s gross salary....
1. Write a function named "countPositiveNegative" that accepts an array of integers, its size and return...
1. Write a function named "countPositiveNegative" that accepts an array of integers, its size and return the number of positive and negative in the array through the use of parameters. In addition, it also returns the number of 0s in the array as the return value. For example, array of {10, 20, -30, -40, 50, 0, 60} will return 4 for positives, 2 for negatives and 1 for 0's as the return value. 2. Write a function named "rotateRight" that...
Java Program Write a method called “fillMatrix” that takes two integers rows and cols and returns...
Java Program Write a method called “fillMatrix” that takes two integers rows and cols and returns a 2D array of integers of size rows x cols where the value of element [row][col] is row + col. Write a short program to test your method.
Write a method that take in an array of integers, find the maximum and minimum, and...
Write a method that take in an array of integers, find the maximum and minimum, and return an array containing four elements in the following order. max integer, max integer index, min integer, min integer index
Question 5: Recommend / Explain a C++ program which uses an array of 20 integers whose...
Question 5: Recommend / Explain a C++ program which uses an array of 20 integers whose input is taken by user, the array is passed to a functions named i.e. smallest(int A[20) and largest(int B[20]) to determine minimum and maximum values respectively. Also create a function named modify(int *p) which modifies the value at the index given by user.
In this lab, you complete a partially prewritten C++ program that uses an array. The program...
In this lab, you complete a partially prewritten C++ program that uses an array. The program prompts the user to interactively enter eight batting averages, which the program stores in an array. The program should then find the minimum and maximum batting average stored in the array as well as the average of the eight batting averages. The data file provided for this lab includes the input statement and some variable declarations. Comments are included in the file to help...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT