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
What is a true job in the information age?​
Gelneren [198K]

Answer:

apple

you get a lot of information about the technology you paid for.

if this was not helpful comment and I’ll fix it!

3 0
3 years ago
Which of the following is the smallest aperture (f-stop) opening?
Firlakuza [10]

Answer:

E) f/16

Explanation:

6 0
3 years ago
_______ is identical to the conventional typewriter keyboard
NeX [460]

Answer:

A

Explanation:

:)

4 0
3 years ago
Read 2 more answers
Helpppppp
Advocard [28]

here's a good expiation

Explanation:

a good and cheap way to remove acne scars from your face is to put vasaline only on the scar. do this about 3 times a day and keep it on overnight as well. in a couple of days the scar will peel leaving a new layer of skin on the bottom. this layer will be scar free! make sure you dont put vasaline on your entire face.

8 0
3 years ago
write pseudocode to represent the logic of a program that allows the user to enter two values. The program outputs the sum of an
valkas [14]

The pseudocode representing the above described logic of a program is:

start

input num1

input  num2

set product  =  num1*num2

output product

stop

See the related flow chart is attached.

<h3>What is a pseudocode?</h3>

Pseudocode is a precise yet comprehensible explanation of what a computer program or algorithm must perform, written in normal language rather than programming language.

Pseudocode is occasionally used as a detailed phase in the development of a program.

Learn more about Pseudocode:
brainly.com/question/24953880
#SPJ1

4 0
2 years ago
Other questions:
  • Write a Java method to delete a record from a B-tree of order n.
    13·1 answer
  • In your own words, explain the role of scientific investigation in the development of the Theory of Evolution.
    6·1 answer
  • How are devices connected to each other via Bluetooth? Choose two answers.
    11·1 answer
  • What is one disadvantage of accessing the Internet through a public search engine such as Google or Yahoo?
    10·2 answers
  • Important tools used in the _____ phase of the DMAIC process include a project charter, a description of customer requirements,
    10·1 answer
  • In Rizzati Corp, vice presidents in departments such as engineering, manufacturing, IT, and human resources report directly to t
    15·1 answer
  • Richard needs to copy information from another slide presentation that uses a different design template. To ensure that the info
    10·1 answer
  • Write 4 types of viruses , explain them briefly.
    7·1 answer
  • Which tab is the "page break" command found on? (there are two!) *
    5·1 answer
  • What are 2 ways to send a message to your client when signed in as an accountant user?.
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!