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
You are responsible for performing all routine maintenance on your company's laser printers. Which of the following maintenance
Luden [163]

Answer:

B. installing the maintenance kit

Explanation:

page count keeps track of how many number of pages that have been printed since the installation of the last maintenance kit. When a new maintenance kit is installed on most Laser printers, the page count is reset because it does not automatically clears most times, hence, there's the need to clear the count manually.

4 0
3 years ago
What is ur Favorite anime
jok3333 [9.3K]

Answer:

one piece lol

Explanation:

8 0
3 years ago
Fill in the blank
EastWind [94]

Answer:

It is called the ENQUIRE database

Explanation: got it right boooiiiii

7 0
3 years ago
Read 2 more answers
Why is network security important? Check all of the boxes that apply. A. Network security allows organizations to continue to fu
serious [3.7K]

Answer:

A. Network security allows organizations to continue to function.

C. Network security keeps intruders out of the network.

D. Network security prevents personal information from getting into the wrong hands.

Explanation:

Network security is a very important concept in networking. Mitigating cyber attacks like key logging, malicious software attacks, reconnaissance attacks, DOS attacks etc, have saved so many companies from bankruptcy and death.

Security in networks helps to prevent attackers from obtaining user personal information like Bank detail, health history etc.

5 0
3 years ago
Is megan the stallion hot
astraxan [27]

Answer:

Explanation:

Cool

8 0
3 years ago
Read 2 more answers
Other questions:
  • Suppose your company has decided that it needs to make certain busy servers faster. Processes in the workload spend 60% of their
    5·1 answer
  • Explain the third <br> generation
    6·1 answer
  • How to select the entire table in microsoft excel
    11·1 answer
  • Some classes, like the ArrayList class, use angle brackets in their documentation and their declaration. For example, the Java d
    5·1 answer
  • A ________ is a member function that is automatically called when a class object is
    6·1 answer
  • Write HTML code for inserting an image "cricket.jpeg" in size 500 width and 400 height.
    12·1 answer
  • Which osi/iso layer is responsible for determining the best route for data to be transferred?
    5·1 answer
  • How does natural gas move through pipelines from the well head to the end user thousands of miles away
    5·1 answer
  • If you're connected to a switch and your NIC is in promiscuous mode, what traffic would you be able to capture
    15·1 answer
  • Which data type is the correct choice to store the names of all the hockey players who have scored 3 or more goals in a single g
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!