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]
4 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]4 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
Give a real life of an if statement
bogdanovich [222]

Answer:

If Joe wants to eat an apple then he eats an apple.

Explanation:

The if statement checks if Joe "wants to eat an apple", if it turns out he does not then nothing will happen.

7 0
3 years ago
When replacing a thermostat or water pump, coolant drained from the cooling system should be ________.
Alchen [17]

Answer:

Explanation:

Disposed of in a contained way/recycled.

5 0
3 years ago
Lesson 2.7 Code Practice #2
scoundrel [369]

Answer:

no se ve unu ........unu

5 0
3 years ago
1. A database table can hold ??
IRINA_888 [86]

Answer:

who are interested and I have been trying to

3 0
3 years ago
Is the Internet dangerous?
VARVARA [1.3K]

Many people would answer this in many different ways. In my personal opinion, it's a yes. It's a yes because it makes it easier for people to track you down (finding your iep) and it's easy for someone to take your identity. It's also dangerous for children and teens (even young adults) because there are many people wanting them, and wanting to meet them in public and things like that. I hope I answered your question! (:

8 0
3 years ago
Read 2 more answers
Other questions:
  • Use the image below to answer this question.
    14·1 answer
  • TRUE OR FALSE, databases allow you to search for content on the internet based on certain criteria (PLS ANSWER RIGHT)
    10·2 answers
  • You often insert your company's logo into documents you create. One way to make it easier for you to quickly insert it is to sav
    10·1 answer
  • Write a function named get_my_age that returns your age as an int (this is YOUR age, so if you were 21 you would return the numb
    11·1 answer
  • A device (or a software program on a computer) that can monitor data traveling on a network is known as a socket sniffer. ______
    15·1 answer
  • Service that connects on-premises software appliances with cloud based storage is ______
    10·1 answer
  • Which tool will select the lines of a sketch in digital software?
    7·1 answer
  • Jeremy has created a document that has images and a chart. The chart has to be updated manually, and double-clicking on the char
    15·1 answer
  • Your assignment is to write an assembly language program which read a string and print it in uppercase. This program asks the us
    11·1 answer
  • State two function of protein in the body
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!