When analyzing data sets, such as data for human heights or for human weights, a common step is to adjust the data. This can be done by normalizing to values between 0 and 1, or throwing away outliers. For this program, adjust the values by subtracting each value from the maximum. The input begins with an integer indicating the number of integers that follow. Assume that the list will always contain between 1 and 20 integers. Ex: If the input is: 5 30 50 10 70 65 the output is: 40 20 60 0 5 For coding simplicity, follow every output value by a space, even the last one. Your program must define and call a method: public static int getMaxInt(int[] listInts, int listSize) import java.util.Scanner; public class LabProgram { public static void main(String[] args) { Scanner scnr = new Scanner(System.in); // Read the number of integers int listSize = scnr.nextInt(); // Create an array to store the integers int[] listInts = new int[listSize]; // Read the integers into the array for (int i = 0; i < listSize; i++) { listInts[i] = scnr.nextInt(); } // Call the getMaxInt method to find the maximum value int max = getMaxInt(listInts, listSize); // Adjust the values and print the result for (int i = 0; i < listSize; i++) { int adjustedValue = max - listInts[i]; System.out.print(adjustedValue); // Add a space after each value except the last one if (i < listSize - 1) { System.out.print(" "); } } // Close the scanner scnr.close(); } // Define the getMaxInt method to find the maximum value in the array public static int getMaxInt(int[] listInts, int listSize) { int max = listInts[0]; for (int i = 1; i < listSize; i++) { if (listInts[i] > max) { max = listInts[i]; } } return max; } }
When analyzing data sets, such as data for human heights or for human weights, a common step is to adjust the data. This can be done by normalizing to values between 0 and 1, or throwing away outliers. For this program, adjust the values by subtracting each value from the maximum. The input begins with an integer indicating the number of integers that follow. Assume that the list will always contain between 1 and 20 integers.
Ex: If the input is:
5 30 50 10 70 65
the output is:
40 20 60 0 5
For coding simplicity, follow every output value by a space, even the last one.
Your program must define and call a method:
public static int getMaxInt(int[] listInts, int listSize)
import java.util.Scanner;
public class LabProgram {
public static void main(String[] args) {
Scanner scnr = new Scanner(System.in);
// Read the number of integers
int listSize = scnr.nextInt();
// Create an array to store the integers
int[] listInts = new int[listSize];
// Read the integers into the array
for (int i = 0; i < listSize; i++) {
listInts[i] = scnr.nextInt();
}
// Call the getMaxInt method to find the maximum value
int max = getMaxInt(listInts, listSize);
// Adjust the values and print the result
for (int i = 0; i < listSize; i++) {
int adjustedValue = max - listInts[i];
System.out.print(adjustedValue);
// Add a space after each value except the last one
if (i < listSize - 1) {
System.out.print(" ");
}
}
// Close the scanner
scnr.close();
}
// Define the getMaxInt method to find the maximum value in the array
public static int getMaxInt(int[] listInts, int listSize) {
int max = listInts[0];
for (int i = 1; i < listSize; i++) {
if (listInts[i] > max) {
max = listInts[i];
}
}
return max;
}
}
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 2 images