Question

In: Computer Science

This assignment involves developing a program that prompts the user to enter a series of 10...

This assignment involves developing a program that prompts the user to enter a series of 10 integers and then determines and displays the largest and smallest values entered.

Your solution must use at least the following variables: counter: A counter to count how many integers were entered

a Number: The integer most recently input by the user,

smallest: The smallest number entered so far, largest: The largest number entered so far.

Write three separate programs for this assignment:

Name the first program HiLoWhile and use a while construct in the solution.

Name the second program HiLoFor and use a for construct in the solution.

Name the third program HiLoDoWhile and use a do-while construct in the solution.

Write the pseudocode for ONLY the HiLoWhile program.

IN JAVA

Solutions

Expert Solution

The programs are written below, and they all use the variables required above, and process the 10 integer inputs to calculate and print the smallest and largest values.

The HiLoWhile program is:

import java.util.Scanner;  // Import Scanner class to get user input

public class Main{

     public static void main(String []args){
        Scanner scan = new Scanner(System.in);
        int counter = 0;
        int latest_input = 0;
        int smallest = 0;
        int largest = 0;
        
        int i = 0;
        while (i < 10) { 
            int input = scan.nextInt();
            counter++;
            latest_input = input;
            if (input < smallest) {
                smallest = input;
            }
            if (input > largest) {
                largest = input;
            }
            i++;
        }
        
        System.out.println("The largest integer is: " + largest);  
        System.out.println("The smallest integer is: " + smallest);  
     }
}

The HiLoFor program is:

import java.util.Scanner;  // Import Scanner class to get user input

public class Main{

     public static void main(String []args){
        Scanner scan = new Scanner(System.in);
        int counter = 0;
        int latest_input = 0;
        int smallest = 0;
        int largest = 0;
        
        for (int i = 0; i < 10; i++) { 
            int input = scan.nextInt();
            counter++;
            latest_input = input;
            if (input < smallest) {
                smallest = input;
            }
            if (input > largest) {
                largest = input;
            }
        }
        
        System.out.println("The largest integer is: " + largest);  
        System.out.println("The smallest integer is: " + smallest);  
     }
}

The HiLoDoWhile program is:

import java.util.Scanner;  // Import Scanner class to get user input

public class Main{

     public static void main(String []args){
        Scanner scan = new Scanner(System.in);
        int counter = 0;
        int latest_input = 0;
        int smallest = 0;
        int largest = 0;
        
        int i = 0;
        do { 
            int input = scan.nextInt();
            counter++;
            latest_input = input;
            if (input < smallest) {
                smallest = input;
            }
            if (input > largest) {
                largest = input;
            }
            i++;
        } while (i < 10);
        
        System.out.println("The largest integer is: " + largest);  
        System.out.println("The smallest integer is: " + smallest);  
     }
}

The psuedocode for HiLoWhile program is:

BEGIN
  Counter = 0
  Latest_input = 0
  Smallest = 0
  Largest = 0

  i = 0
  WHILE i < 10 
     Input_int = INPUT()
     Counter++
     Latest_input = Input_int
     IF Input_int < Smallest THEN
         Smallest = Input_int
     END IF
     IF Input_int > Largest THEN
         Largest = Input_int
     END IF
     i++

  PRINT("The largest integer is: ", Largest)  
  PRINT("The smallest integer is: ", Smallest)
END

I hope that answers all four parts of your question.


Related Solutions

Write a program that prompts the user to enter a series of strings, but with each...
Write a program that prompts the user to enter a series of strings, but with each string containing a small integer. Use a while loop and stop the loop when the user enters a zero. When the loop has finished, the program should display: the number of user inputs (not counting the final zero input). the total of the integers in the strings entered. the average of the integers accurate to one decimal place. Any help is greatly appreciated, this...
JAVA Write a test program that prompts the user to enter a series of integers and...
JAVA Write a test program that prompts the user to enter a series of integers and displays whether the series contains runLength consecutive same-valued elements. Your program’s main() must prompt the user to enter the input size - i.e., the number of values in the series, the number of consecutive same-valued elements to match, and the sequence of integer values to check. The return value indicates whether at least one run of runLength elements exists in values. Implement the test...
write a c++ program that prompts a user to enter 10 numbers. this program should read...
write a c++ program that prompts a user to enter 10 numbers. this program should read the numbers into an array and find the smallest number in the list, the largest numbers in the list the sum of the two numbers and the average of the 10 numbers PS use file I/o and input error checking methods
( USE C++ ) The program prompts the user to enter a word. The program then...
( USE C++ ) The program prompts the user to enter a word. The program then prints out the word with letters in backward order. For example, if the user enter "hello" then the program would print "olleh" show that it works .
Write a program that prompts the user to enter a positive integer and then computes the...
Write a program that prompts the user to enter a positive integer and then computes the equivalent binary number and outputs it. The program should consist of 3 files. dec2bin.c that has function dec2bin() implementation to return char array corresponding to binary number. dec2bin.h header file that has function prototype for dec2bin() function dec2binconv.c file with main function that calls dec2bin and print results. This is what i have so far. Im doing this in unix. All the files compiled...
Problem 4 : Write a program that prompts the user to enter in an integer and...
Problem 4 : Write a program that prompts the user to enter in an integer and then prints as shown in the example below Enter an integer 5 // User enters 5 1 2 2 3 3 3 4 4 4 4 5 5 5 5 5 Bye
IN C++ Write a program that prompts the user to enter the number of students and...
IN C++ Write a program that prompts the user to enter the number of students and each student’s name and score, and finally displays the student with the highest score (display the student’s name and score). Also calculate the average score and indicate by how much the highest score differs from the average. Use a while loop. Sample Output Please enter the number of students: 4 Enter the student name: Ben Simmons Enter the score: 70 Enter the student name:...
JAVA Write a program that will compare two names. The program prompts the user to enter...
JAVA Write a program that will compare two names. The program prompts the user to enter two names for a comparison. If the names are same, the program states that. If the names are different, the program converts both names to UPPERCASE, and compares then again. If they are equal, the programs displays a message stating that names are equal if CASE is ignored. Otherwise, the program prints names with a message that names are not equal.  Check also if there...
Write a program that prompts user to enter integers one at a time and then calculates...
Write a program that prompts user to enter integers one at a time and then calculates and displays the average of numbers entered. Use a while loop and tell user that they can enter a non-zero number to continue or zero to terminate the loop. (Switch statement) Write a program that prompts user to enter two numbers x and y, and then prompts a short menu with following 4 arithmetic operations: Chose 1 for addition Chose 2 for subtraction Chose...
Write a test program that prompts the user to enter a sequence of numbers ending with...
Write a test program that prompts the user to enter a sequence of numbers ending with 0, and invokes this method to return the largest number in the input. Use inheritance and polymorphism approach. in java please
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT