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

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
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
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education