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
lisabon 2012 [21]
3 years ago
7

Two Smallest (20 points). Write a program TwoSmallest.java that takes a set of double command-line arguments and prints the smal

lest and second-smallest number, in that order. It is possible for the smallest and second-smallest numbers to be the same (if the sequence contains duplicate numbers). Note: display one number per line. Hint: Double.MAX_VALUE is the largest real number that can be stored in a double variable. java TwoSmallest 17.0 23.0 5.0 1.1 6.9 0.3 0.3 1.1 java TwoSmallest 1.0 35.0 2.0 1.1 6.9 0.3 0.3 6.7 0.3 0.3
Computers and Technology
1 answer:
Ivan3 years ago
4 0

Answer:

Written in Java

import java.util.*;

public class Main {

   public static void main(String args[]) {

     int n;

     Scanner input = new Scanner(System.in);

     n = input.nextInt();

     double nums []= new double [n];

     for (int i=0; i<n;i++)

     {

         nums[i] = input.nextDouble();

     }

     

     Arrays.sort(nums);

     System.out.println("The two smallest are: ");

     for (int i=0; i<2;i++)

     {

         System.out.println(nums[i]);

     }

   }

}

Explanation:

This line declares number of input

     int n;

This line calls the Scanner function

     Scanner input = new Scanner(System.in);

This line gets input from user

     n = input.nextInt();

This line declares an array of n elements

     double nums []= new double [n];

The following iteration gets input into the array

     for (int i=0; i<n;i++)

     {

         nums[i] = input.nextDouble();

     }

This line sorts the array

     Arrays.sort(nums);

The following iteration prints the two smallest

     System.out.println("The two smallest are: ");

     for (int i=0; i<2;i++)

     {

         System.out.println(nums[i]);

     }

You might be interested in
Network layer functionalities can be broadly divided into data plane functionalities and control plane functionalities. What are
s2008m [1.1K]

Answer:

See explaination for the main functions of the data plane and Of the control plane.

Explanation:

A Data plane is used in a network, it is also known as forwarding plane. The main responsibility of a data plane is to carry forward the packets or data between different clients of the network.

A Control plane used in the network is responsible for establishing a connection information. That is a Control plane connects different controls by exchanging their routing and forwarding information.

4 0
3 years ago
Read 2 more answers
What does ADAC mean <br> pls answer quickly i will mrk brainliest
kirza4 [7]

Answer:

Allgemeiner Deutscher Automobil-Club 

7 0
3 years ago
Read 2 more answers
What is computer science
solong [7]

Answer:

computer science is the study of the principles and use of computers.

Explanation:

8 0
3 years ago
Read 2 more answers
If you are planning to carry a large balance on your credit card, which of the following credit card features should you look fo
fredd [130]
You should use an American Express.
5 0
3 years ago
What can be written to perform a certain number of iterations or to iterate until a specific result is achieved?
OlgaM077 [116]

Answer:

The answer to this question is given below in the explanation section. However, the correct option is B. i.e a for loop.

Explanation:

The correct answer to this question is for-loop. Beause, in the for loop is written to perform a certain number of iterations or to iterate until a specific result is achieved.

for example, to calculate the average of 10 numbers, we use the for loop to iterate statements written in its body 10 times to calculate the average.

when the specific numbers of the iteration are reached it will get terminated.

for example

for (int i=0; i<=10; i++)

{

// perfrom average, code

}

this loop iterate 10 times or less, when it reached above the limit it gets stopped.

however, the other options are not correct, because an ordered data structure is like a list of order data, print function print something to the user or on screen. while an array is like a list of data of the same data type.

7 0
3 years ago
Other questions:
  • Which element in Access is an ideal data source?
    12·2 answers
  • Suppose there is a class Roster. Roster has one variable, roster, which is a List of tuples containing the names of students and
    6·1 answer
  • Which devices are managed through device management?
    5·1 answer
  • All of the following are ways to save money on transportation except :
    7·1 answer
  • Henry has created a software that manages a database of all his music.he wishes to run the software on another computer system t
    5·1 answer
  • 4.3 Code Practice<br> edhisve
    13·1 answer
  • Hi need help on this <br> what is cyberspace
    14·1 answer
  • Where are some places that cyberbullying occurs? Check all that apply.
    15·1 answer
  • Describe the purpose of functional dependency in computer science.<br>​
    13·1 answer
  • 1. What is the difference between a group and a topic?
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!