Java Reference
In-Depth Information
4. Write a method that finds the number of occurrences of the integer specified as the
first parameter in the array of integers that is specified as the second parameter. Write
a full program to test the method.
5. Write a method that takes as input a variable number of integers. The method should
return the average of the integers as a double . Write a full program to test the method.
6. Write a method that takes as input a two-dimensional square array of integers. The
method should return the sum of the elements of the top-right to bottom-left diagonal.
Write a full program that tests the method.
7. Write a method that takes as input a two-dimensional array of integers. The method
should return a one-dimensional array of elements of type double that contains the
average for each row. Write a full program that tests the method.
8. Write a method that takes as input a two-dimensional array of integers. The method
should return a one-dimensional array of elements of type double that contains the
average for each column. You can assume that the array is non-ragged. Write a full
program that tests the method.
9. Write a method that tests if the two-dimensional array that is specified as a parameter
is ragged. Write a full program that tests the method.
10. Write a method that takes as input a two-dimensional array of integers. The method
should return the biggest integer in the array. Write a full program that tests the
method.
11. Write a method that takes as input an array of integers. The method should reverse
the array. Write a full program that tests the method.
12. Write a method that takes as input an array of doubles. The method should return
the second largest double in the array. Write a full program that tests the method.
13. Write a method that takes as input an array of integers and returns an array of
three integers. You can assume that the input array contains at least three elements.
The returned array should contain the three consecutive elements in the input array
with the biggest sum. For example, if the input array is
{
3,6,5,2,6
}
, then the output
array should be:
because 3+6+5=14, which is bigger than 6+5+2=13 and
5+2+6=13. Write a full program that tests the method.
{
3,6,5
}
5.10 Lab
The bubble sort is the simplest kind of sort. Given an array, the bubble sort goes through
the array from left to right and compares consecutive numbers. If two numbers are in the
wrong order, then it swaps them. Consider the following example:
1076321
The bubble sort will first swap 10 and 7 and
create the new array that is shown below.
7106321
 
Search WWH ::




Custom Search