Write your code in the file SmallLargest.java. Write your test cases in assign4-
ID: 3629989 • Letter: W
Question
Write your code in the file SmallLargest.java. Write your test cases in assign4-testcases.txt.We wish to write a program that takes a set of numbers and determines the largest and smallest numbers.
Ask the user for the following information, in this order:
A terminating value (real number). The user will enter this value again later, to indicate that he or she is finished providing input.
A sequence of real numbers. Keep asking for numbers until the terminating value is entered.
Compute and output the largest and smallest real number, in that order. It is possible for the largest and smallest numbers to be the same (if the sequence contains all the same numbers). Blue text below indicates notes to you, and are not actually part of the output/input.
Example:
java SmallLargest
123 [this is the terminating value, not part of the set of numbers]
17
23.5
10
15.2
30
8
16
123 [this is the terminating value again, indicating that the user is done]
RESULT: 30.0
RESULT: 8.0
Explanation / Answer
please rate - thanks
import java.util.*;
public class SmallLargest
{public static void main(String[] args)
{double n,term,max,min;
Scanner in=new Scanner(System.in);
System.out.print("Enter the number to use as the terminating value: ");
term=in.nextDouble();
System.out.print("Enter a number "+term+" when done ");
n=in.nextDouble();
max=n;
min=n;
while(n!=term)
{if(n>max)
max=n;
if(n<min)
min=n;
System.out.print("Enter a number "+term+" when done ");
n=in.nextDouble();
}
System.out.println("Results: biggest number= "+max+" smallest number= "+min);
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.