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]; } } System.out.println(); 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];
}
} System.out.println();
return max;
}
}
![Output is nearly correct, but whitespace differs. See highlights below.
Input 5 30 50 10 70 65
Your output
2:Compare output
Expected output 40 20 60 05
40 20 60 05
Output is nearly correct, but whitespace differs. See highlights below.
Input 75 10 15 20 25 30 35
Your output
w ↑
30 25 20 15 10 5 0
Expected output 30 25 20 15 10 5 0
Special character legend
Special character legend](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F6b67a6a2-2d8c-4553-99c2-3c44a5ebdd4f%2Faa353468-5d09-413e-a2c9-cd8401256cca%2Fhsmr389_processed.png&w=3840&q=75)
![](/static/compass_v2/shared-icons/check-mark.png)
Your code looks mostly correct, but there are a couple of issues. First, you need to adjust the values by subtracting each value from the maximum, as specified in the problem statement. Second, you should not have an extra System.out.println();
statement inside the getMaxInt
method, as it will cause an extra newline to be printed.
Step by step
Solved in 3 steps
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)