Question

Write a ( JAVÅ) program which reads (from the keyboard) numbers (doubles) until a zero is...

Write a ( JAVÅ) program which reads (from the keyboard) numbers (doubles) until a zero is input and computes the maximum and minimum of all the read numbers (excluding the terminating zero). Note: you must allow for negative as well as positive numbers. Hint: look at java.lang.Double.MAX_VALUE and java.lang.Double.MIN_VALUE.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

import java.util.Scanner;

public class MaxMin {
   public static void main(String[] args){
       Scanner s=new Scanner(System.in);    //create scanner object to read input
       double max=0,min=0,num;
       System.out.println("Enter numbers, terminate with 0");
       do{
           num=s.nextDouble();    //read a double number from keyboard
           if(num>max){
               max=num;   //assign number to max if number is greater than max
           }
           if(num<min){
               min=num;    //assign number to min if number is lesser than min
           }
       }while(num!=0);
       System.out.println("Maximum: "+max);    //display the maximum number
       System.out.println("Minimum: "+min);    //display the minimum number
   }
}

Add a comment
Know the answer?
Add Answer to:
Write a ( JAVÅ) program which reads (from the keyboard) numbers (doubles) until a zero is...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 1. Write a program that reads a sequence of numbers from the keyboard, and displays the...

    1. Write a program that reads a sequence of numbers from the keyboard, and displays the smallest number. The sequence has at least one number and is terminated by -999(-999 will not appear in the sequence other than as the end marker). 2. Write a program which requests an integer input n from the keyboard and computes the sum of square of k for all k from 1 to n(inclusive). use java

  • Write a program that inputs up to 100 real numbers from the keyboard (one at a...

    Write a program that inputs up to 100 real numbers from the keyboard (one at a time). When a number greater than 1.0e9 is input the keyboard input will stop. Then the following statistic for the input data will be computed and printed out to the screen. a) average b) standard deviation c) minimum value d) maximum value e) range = (maximum-minimum)/2 f) the number of times zero is input **Note: this is a program in C++** 3) Write a...

  • C++ PROGRAMING Write a program that reads numbers from the input stream until a zero is...

    C++ PROGRAMING Write a program that reads numbers from the input stream until a zero is encountered. Display the average (rounded down to an integer), the maximum number and the minimum number. Assume that numbers entered will be between 1 and 1000. For example: Enter a number: 33 Enter a number: 88 Enter a number: 77 Enter a number: 22 Enter a number: 66 Enter a number: 55 Enter a number: 0 Average: 56 Max: 88 Min: 22 Another example:...

  • In this exercise, write a complete Java program that reads integer numbers from the user until...

    In this exercise, write a complete Java program that reads integer numbers from the user until a negative value is entered. It should then output the average of the numbers, not including the negative number. If no non-negative values are entered, the program should issue an error message. You are required to use a do-while loop to solve this problem. Solutions that do not use a do-while loop will be given a zero. Make sure to add appropriate comments to...

  • using c++ write a program that reads numbers from the user until the user enters a...

    using c++ write a program that reads numbers from the user until the user enters a Sentinel. Use a Sentinel of -999. Ignore all negative numbers from the user input. Do the following: 1. Output the sum of all even numbers

  • Using Racket Create a Racket procedure compute_pos that reads numbers from the keyboard until 0 is...

    Using Racket Create a Racket procedure compute_pos that reads numbers from the keyboard until 0 is read, count how many positive numbers are read, and also compute the sum of only positive numbers, and display the count and the sum of positive numbers in different lines. Note that 0 is not included in the computations. For example, if user enters: 3 6 -4 12 15 -9 -24 4 -3 -5 1 0 then your procedure should print positive count: 6...

  • Part A Write a Java program that reads an integer n from the keyboard and loops...

    Part A Write a Java program that reads an integer n from the keyboard and loops until −13 ≤ n ≤ 13 is successfully entered. A do-while loop is advised. Part B Write a Java program that reads an integer n from the keyboard and prints the corresponding value n!. [This is n factorial]. You must verify that the input integer satisfies the constraint 0 ≤ n ≤ 13; keep looping until the constraint is satisfied.   Will give thumbs up...

  • in C The preceding LML program reads two numbers from the keyboard and determines and prints the larger value. Note the use of the instruction +4107 as a conditional trans- fer of control, much...

    in C The preceding LML program reads two numbers from the keyboard and determines and prints the larger value. Note the use of the instruction +4107 as a conditional trans- fer of control, much the same as C's if statement. In-Class Tasks Write LML programs that accomplish each of the following tasks: Use a sentinel-controlled loop to read 10 positive integers and compute and print their sum 1. 2. Use a counter-controlled loop to read seven numbers, some positive and...

  • (Count positive and negative numbers and compute the average of numbers) Write a program that reads...

    (Count positive and negative numbers and compute the average of numbers) Write a program that reads an unspecified number of integers, determines how many positive and negative values have been read, and computes the total and average of the input values (not counting zeros). Your program ends with the input 0. Display the average as a floating-point number. If you entire input is 0, display 'No numbers are entered except 0.' *So I think my code is looping because the...

  • Q1. Write a C++ program that reads two integers a, and, b on the keyboard to...

    Q1. Write a C++ program that reads two integers a, and, b on the keyboard to calculate: U = (a + b)2 and V = (a - b)2 Q2. Write a C++ program to read a sequence of positive integers and to display the largest integer of that sequence. Use a negative integer to indicate the end of the data entry.

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT