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 the following scenarios falls into the category of network crimes?
solong [7]

Answer:

B

Explanation:

Hope it helps!

3 0
2 years ago
Read 2 more answers
Describe a situation in which you have experienced harm as a consequence of a failure of computer security. Was the failure mali
frutty [35]

Answer: The goals of computer security are to protect computers and users from data theft or loss as well as damage to any part of the computer.

Explanation: Common means of achieving computer security are firewalls, anti-virus software and this can fail due to hardware problems  or   weaknesses that prevent malicious attacks.

To answer this question, think of a time when you experienced any one of these. For example, personally, I was once an unfortunate victim of a general malicious attack that took advantage of a weakness in my anti-virus software. After clicking on a link on a dodgy website, a virus was installed on my computer. My computer finally crashed, without any hope of restarting it. I lost all my data and I had to buy a new computer.  This was a malicious attack.

However, sometimes people can be specifically targeted to steal their data or monitor their activities.  

7 0
3 years ago
PLEASE HELP ME ASAP!!! Looking at the misty rain and fog (pictured above) Explain at least two defensive driving techniques you
JulsSmile [24]
1.Slow down 2. Break earlier
7 0
3 years ago
Keep true , never be ashamed of doing right decide on what you think is right and stick to it.
Doss [256]
This is the quote of T.S. Eilot
5 0
3 years ago
Write a program in c++ to read two integers, calculate and print the smallest
Shalnov [3]

Answer:

#include<iostream>

using namespace std;

int main (){

int n1, n2;

cout<<"Enter 1st number";

cin>>n1;

cout<<"Enter 2nd number";

cin>>n2;

if(n1<n2){

cout<<"The 1st number is the smallest"<<endl<<" is= "<<n1;

}

else{

cout<<"The 2nd number is the smallest"<<endl<<" is= "<<n2;

}

}

return 0;

3 0
3 years ago
Other questions:
  • While a hard drive is running, even a slight bump against the computer may cause the
    9·2 answers
  • Larry does not want to save his Internet browsing details on his computer what files delete to clear his information from the co
    7·1 answer
  • Your network administrator finds a virus in the network software. Fortunately,
    13·1 answer
  • Name that red flag asigment
    15·2 answers
  • What is sun and what does it do?
    12·2 answers
  • Searching for a particular record in a database is called “querying the data.”<br> True<br> False
    9·2 answers
  • Software que busca, detecta y elimina malware tipo espía; puede instalarse en la computadora de manera aislada o en conjunto con
    11·1 answer
  • You want to be able to identify the services running on a set of servers on your network. Which tool would best give you the inf
    11·1 answer
  • How would you want to change the copyright laws?
    11·1 answer
  • Identifying correction services tasks
    14·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!