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
5. Played electronically by manipulating images on a television screen produced by a
kenny6666 [7]

Answer:

1) Video Games

2) Gunpei Yokoi

Explanation:

1) Video games are electronic games played off electronic consoles which are connected to Visual Display Units such as desktops or laptops and flat=screen televisions. The games are created in such a way that images can be manipulated using a pad and controlled by the computer program.

2) Gunpei Yokoi person who made the "game boy" and "game and watch" hand-held games.

He was recognized posthumously for his achievements in 2003 when he was offered a lifetime achievement award from the international game developers association.

Cheers

3 0
3 years ago
What is an rgv in coding
Mashcka [7]

The RGB color model is an additive color model in which red, green and blue light are added together in various ways to reproduce a broad array of colors.

4 0
4 years ago
Read 2 more answers
The e-mail address of any third party recipient of an e-mail belongs in which field?
kifflom [539]
B, the Cc part of the email.
6 0
3 years ago
What is the best way to appeal to an audience in any medium ?
BigorU [14]

Answer:

I think it's D

Explanation:

The best way to appeal is with emotions

8 0
3 years ago
Without any formal planning, the president of a software company remarks in a speech that new technologically advanced software
ahrayia [7]

Answer:

<em>Imposed project deadlines.</em>

Explanation:

The term of project management imposed deadline<em> refers mainly to the calendar-based dividing line used to determine a fixed time or date on which the project management team has projected and/or developed that the particular schedule of work and/or schedule of work events.</em>

6 0
4 years ago
Other questions:
  • Jane is a postproduction crewmember for a film. Her responsibilities include arranging all the scenes that have been shot into t
    7·1 answer
  • In addition to talking to other doctors remotely, telegraphy technology?
    5·1 answer
  • Sponse that best answers the question.
    11·2 answers
  • What is the result of giving the which utility the name of a command that resides in a directory that is not in your search path
    10·1 answer
  • Which of the following is the formula used to calculate the risk that remains after you apply controls? a. ALE=SLExARO b. Total
    9·1 answer
  • Network address translation is useful because it enables
    5·1 answer
  • The ability to adapt to increases or decreases in demand for processing or data storage is known as ________. Group of answer ch
    9·2 answers
  • Write a program that performs the following tasks: Display a friendly greeting to the user Prompt the user for the value to conv
    13·1 answer
  • One subtask in the game is to ‘refuel a car’. Explain why ‘refuel a car’ is an abstraction.
    13·1 answer
  • Why do we need to use a VPN service?
    9·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!