Add a method removeMin to the Student class of Section 7.4 that removes the mini
ID: 3810400 • Letter: A
Question
Add a method removeMin to the Student class of Section 7.4 that removes the minimum score without calling other methods. Compute the alternating sum of all elements in an array. For example, if your program reads the input 1 4 9 16 9 7 44 9 11 then it computes 1 -4 +9 -16 +9 -7 +4 -9 +11 = -2 Write a method that reverses the sequence of elements in an array. For example, if you call the method with the array 1 4 9 16 9 7 4 9 11 then the array is changed to 11 9 4 7 9 16 9 4 1 Write a program that produces ten random permutations of the numbers 1 to 10. To generate a random permutation, you need to fill an array with the numbers 1 to 10 so that no two entries of the array have the same contents. You could do it by brute force, generating random values until you have a value that is not yet in the array. But that is inefficient. Instead, follow this algorithm: Make a second array and fill it with the numbers 1 to 10. Repeat 10 times Pick a random element from the second array. Remove it and append it to the permutation array.Explanation / Answer
7.4 Incomplete Question
Other answers are below::
import java.util.Random;
public class Solution {
public int alternatingSum(int[] array){
int posSum=0,negSum = 0;
//Calculating positive sum
for(int i=0;i<array.length;i=i+2){
posSum = posSum + array[i];
}
//Calculating negative sum
for(int i=1;i<array.length;i=i+2){
negSum = negSum + array[i];
}
return posSum-negSum;
}
public int[] reverseArray(int[] array){
// Creating new array which will store values in reverse array
int[] reverse = new int[array.length];
int index = 0;
for(int i=array.length-1;i>=0;i--){
reverse[index] = array[i];
index++;
}
return reverse;
}
public void permutations(){
Random random = new Random();
int val;
//Running loop 10 times
for(int i=0;i<10;i++){
for(int j=0;j<10;j++){
// Generating random number 1 to 10
val = random.nextInt(10) + 1;
System.out.print(val+" ");
}
System.out.println();
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.