1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
BigorU [14]
3 years ago
5

Write a program TwoSmallest.java that takes a set of double command-line arguments and prints the smallest and second-smallest n

umber, in that order. It is possible for the smallest and second-smallest numbers to be the same (if the sequence contains duplicate numbers).
Computers and Technology
1 answer:
aliina [53]3 years ago
7 0

Answer:

The following code is written in java programming language:

public class TwoSmallest {   //define class

   public static void main(String[] args) {     // define main function

       if (args.length < 2) {     //set the if condition

           System.out.println("Enter double values as command line arguments");

       } else {

           double minimum1 = Double.parseDouble(args[0]), minimum2 = Double.parseDouble(args[1]), n;

           if (minimum1 > minimum2) {    //set the if condition

               double temp = minimum1;

               minimum1 = minimum2;

               minimum2 = temp;

           }

           for (int i = 2; i < args.length; i++) {      //set the for loop

               n = Double.parseDouble(args[i]);

               if (n < minimum1) {

                   minimum2 = minimum1;

                   minimum1 = n;

               } else if (n < minimum2) {

                   minimum2 = n;

               }

           }

           System.out.println(minimum1);

           System.out.println(minimum2);

       }

   }

}

Explanation:

Here, we define a class "TwoSmallest" with public modifier.

Then, we define the main method.

Then, we set if condition and pass condition "args.length < 2".

Then we take three double type variable "minimum1", "minimum2" and "n".

Then, we set the if condition and pass condition if "minimum1 > minimum2", then set double type "temp" variable and swap between temp, minimum1 and minimum2.

Then, we set the for loop which is start from 2 and stops at "args.length"

Then, we set if condition and then we set its else part, after that we print the value of minimum1 and minimum2.

You might be interested in
Which of these statements regarding mobile games is true?
SashulF [63]

Answer:

A. They are typically played in doors.

Explanation:

Most logical answer

8 0
3 years ago
Read 2 more answers
Winners announced tomorrow when I check results ngl I gtg to sleep soon I should see a lot of people tomorrow ^^
kobusy [5.1K]

i am sup by the way. so im guessing i win?

4 0
3 years ago
fill down feature on a formula and you need to keep a cell reference the same which one will allow you to keep the same cell ref
dedylja [7]
A dollar sign after both the letter and the number for each cell reference you want to keep the same will keep it the same when using the fill down/across function.
6 0
3 years ago
What will be the output of the following program? Assume the user responds with a 5.
FrozenT [24]

The output will be: You owe $ 15.0

4 0
3 years ago
Describe four features of a well designed input screen
Sladkaya [172]

Answer:

A well design input screen should:1.Be titled2.Navigation aids should be used

Explanation:

3 0
2 years ago
Read 2 more answers
Other questions:
  • List of functional programming languages
    6·1 answer
  • You have an insurance policy with a $300 premium and a $500 deductible. How much should you expect to pay the insurance company
    15·1 answer
  • By issuing concert tickets on the blockchain, fans can verify transfer of ownership from one digital wallet to another, rather t
    14·1 answer
  • a reviewer is required to enter a reason in the comments field only when a candidate is recommended to be hired. which action ca
    8·1 answer
  • Which one of these variables has an illegal name?
    11·1 answer
  • Jane is debugging a code consisting of 25 lines. The code starts executing at line 11. At line 13, the code calls another method
    10·2 answers
  • When changing the formatting of a spreadsheet to make it more readable, you should use light blue text on a bright blue backgrou
    12·1 answer
  • The TCP _____ is the amount of information that a machine can receive during a session and still be able to process the data.
    5·1 answer
  • A(n) ___________ allows people at two or more locations to interact via two-way video and audio transmissions simultaneously as
    6·1 answer
  • Why is it important to prepare the farm resources before you start working? explain​
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!