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 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 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....
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.
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 JAVA 1. Write up a small program that accepts two integers from the user. Print...
IN JAVA 1. Write up a small program that accepts two integers from the user. Print which of the two values is bigger. If they are the same, print that they are the same. 2. Write a method that accepts three doubles. Calculate and return the average of the three passed double values. 3. Write up a method that accepts a score between 0-10. Print out a message according to the following table. You ay personally decide the boundaries. i.e.,...
THIS IS JAVA PROGRAMMING Write a method that finds the shortest word in an array of...
THIS IS JAVA PROGRAMMING Write a method that finds the shortest word in an array of String values and returns the length, in characters, of that word. The method should use the following header. public static int minLength(String[] array) Write a test program that prompts the user to enter ten strings, store them in an array and invokes this method to return the shortest length, and displays that value. (A near complete program can be found attached to the dropbox)
IN JAVA PLEASE write code to MERGESORT an array of user inputted OBJECTS you have two...
IN JAVA PLEASE write code to MERGESORT an array of user inputted OBJECTS you have two different classes in the program being made as objects in the main (Bunny class and Dog Class). ask the user "what kind of animal would you like to sort?" user chooses the type of animal (bunny or dog), then you ask the user how big would you like the array of animals to be (maximum array size = 20)? and then you ask what...
Java Program: You will be inserting values into a generic tree, then printing the values inorder,...
Java Program: You will be inserting values into a generic tree, then printing the values inorder, as well as printing the minimum and maximum values in the tree. Given main(), write the methods in the 'BSTree' class specified by the // TODO: sections. There are 5 TODOs in all to complete. Ex: If the input is like ferment bought tasty can making apples super improving juice wine -1 the output should be: Enter the words on separate lines to insert...
Write a C program that prompts the user to enter a line of text on the...
Write a C program that prompts the user to enter a line of text on the keyboard then echoes the entire line. The program should continue echoing each line until the user responds to the prompt by not entering any text and hitting the return key. Your program should have two functions, writeStr and readLn, in addition to the main function. The text string itself should be stored in a char array in main. Both functions should operate on NUL-terminated...
Assignment #4 – Student Ranking : In this assignment you are going to write a program...
Assignment #4 – Student Ranking : In this assignment you are going to write a program that ask user number of students in a class and their names. Number of students are limited to 100 maximum. Then, it will ask for 3 test scores of each student. The program will calculate the average of test scores for each student and display with their names. Then, it will sort the averages in descending order and display the sorted list with students’...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT