Question
Asked Mar 31, 2019

Write a program called LoopMinMax that reads in 4 values from the user and prints the lowest and highest value entered. 

Enter a value: 4
Enter a value: 2
Enter a value: 7
Enter a value: 11
Lowest: 2 Highest: 11

check_circleExpert Solution
Step 1

You didn’t mention which language should be used for the given program. Here, I have used JAVA language which is compiled in Eclipse software.

Program plan:

  • Import the required java packages.
  • Define a class named “LoopMinMax”.
    • Define a “main()” method.
      • Declare required variables.
      • Create an object for scanner to get user input.
      • Get the user input and read the values.
      • “if” statement to find highest and lowest value of 4 values.
      • Then, print the lowest and highest value of 4 values.
Step 2

Program:

LoopMinMax.java:

// Import required packages

import java.util.*;

 

// Definition of class

public class LoopMinMax {

 

    // Definition of main() method

    public static void main(String args[]) {

       

        // Declaration of variables

        int i, num, max, min;

       

        // Create an object for scanner

        Scanner s1 = new Scanner(System.in);

       

        // Get the user input

        System.out.print("Enter a value: ");

       

        // Assign first value to num

        num = s1.nextInt();

       

        // Assign num to max

        max = num;

       

        // Assign num to min

        min = num;

       

        // Loop iterates to get next three values from the user

        for (i = 1; i <= 3; i++) {

           

            // Get the user input

            System.out.print("Enter a value: ");

           

            // Assign first value to num

            num = s1.nextInt();

         ...

Want to see the full answer?

See Solution

Check out a sample Q&A here.

Want to see this answer and more?

Solutions are written by subject experts who are available 24/7. Questions are typically answered within 1 hour*

See Solution
*Response times may vary by subject and question
Tagged in

Engineering

Computer Science

Related Computer Science Q&A

Find answers to questions asked by student like you

Show more Q&A add
question_answer

Q: Used Java 4.23 (Financial application: payroll) Write a program that reads the following information...

A: The program would have the following 4 sections:The declaration and initialization of the variables ...

question_answer

Q: in eclipse

A: In operator overloading, the type of arguments defines which function will be called at the run-time...

question_answer

Q: Write a java program called Sales considering the following directions and the sample run. Practice ...

A: The program has the following steps:Declare the variablesReceive the input from the userCalculate th...

question_answer

Q: create a python program that will ask users to input four different manufacturers of cars(e.g Ford, ...

A: Create a class Car and define _init_ () function which will initialize the value of variables manufa...

question_answer

Q: Which command can you use to determine who is logged in on a specific terminal?

A: Different commands are used to determine who is logged in on a specific terminal. These commands are...

question_answer

Q: how can I write a statement in C++ that would print last name, followed by a comma, followed by firs...

A: Given below is the C++ program to print a statement with last name, followed by comma, followed by f...

question_answer

Q: Show that the following grammar is ambiguous: S→AB|aaaB,A→a|Aa,B→b.

A: A grammar is known as ambiguous when there is more than one derivation tree (right most derivation t...

question_answer

Q: 3. Which command can you use to look for the file names status.report? Which command can you use to ...

A: The command used to look for files is ‘find’ command. Find command can be used with many criteria to...

question_answer

Q: Please trace the code and give the correct output

A: Program Instructions:After adding the necessary cstring header file and formatting the output, the p...