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;              }

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter8: Arrays And Strings
Section: Chapter Questions
Problem 6PE
icon
Related questions
Question

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
Transcribed Image Text: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
Expert Solution
steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
Problems on Dynamic Programming
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning