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
The second row of letters on the keyboard is called the______ row
Mkey [24]
The 2nd row of ur keyboard its called home row !

5 0
4 years ago
Read 2 more answers
Copy the countdown function from Section 5.8 of your textbook. def countdown(n): if n &lt;= 0: print('Blastoff!') else: print(n)
Lapatulllka [165]

Answer:

def countdown(n):

   if n <= 0:

       print('Blastoff!')

   else:

       print(n)

       countdown(n-1)

       

def countup(n):

   if n >= 0:

       print('Blastoff!')

   else:

       print(n)

       countup(n+1)

number = int(input("Enter a number: "))

if number >= 0:

   countdown(number)

elif number < 0:

   countup(number)

<u>Outputs:</u>

Enter a number: 3                                                                                                              

3                                                                                                                              

2                                                                                                                              

1                                                                                                                              

Blastoff!

Enter a number: -3                                                                                                              

-3                                                                                                                              

-2                                                                                                                              

-1                                                                                                                              

Blastoff!

Enter a number: 0

Blastoff!

For the input of zero, the countdown function is called.

Explanation:

Copy the countdown function

Create a function called countup that takes one parameter, n. The function counts up from n to 0. It will print the numbers from n to -1 and when it reaches 0, it will print "Blastoff!".

Ask the user to enter a number

Check if the number is greater than or equal to 0. If it is, call the countdown function. Otherwise, call the countup function.

4 0
3 years ago
Hey yall wanna send me some just ask for my phone #
GuDViN [60]

Answer:

Send you some what?

Explanation:

the answer is 12

7 0
3 years ago
A smart refrigerator can use what to detect when you are running low on milk, and then send a reminder to you on a wireless.
Olegator [25]

Answer:

RFID scanning or Barcode reader

Explanation

Smart refrigerators have inbuilt RFID scanning technology that help monitor the stock that is inside your fridge. Once you pass your items through the inbuilt RFID scanner in the fridge, the barcode of your items is cross-referenced with a database and given a unique tag for identification. This technology helps detect and track the stock that is inside your fridge and when you start running low, the RFID can be triggered to send a reminder as a notification on your email or a text message.

3 0
3 years ago
How to insert header and page number in word 2016?
AleksAgata [21]
Insert - Header - choose header of your choice. Page numbers are below the Header icon

3 0
3 years ago
Other questions:
  • WHAT IS SQL AND HOW CAN YOU MEET THE DATA REQUIREMENTS ALSO MAINTAINING DATA INTEGRITY,AND LASTLY STATE THE FULL MEANING OF SQL
    11·1 answer
  • A commonly used font style is _____. superscript periwinkle times new roman point
    7·1 answer
  • Your organization will be handling market trades. You will be required to verify the identify of each customer who is executing
    8·1 answer
  • A program uses two classes: dog and poodle. which class is the base class and which is the derived class?
    7·2 answers
  • _____ involves storing data and running applications outside the company’s firewall. answer grid computing parallel computing cl
    11·1 answer
  • For the following C code assume k and m are passed in x3 and x4 respectively, while result is returned in x4. Compile this code
    14·1 answer
  • The product of two integers is -180 if one of them is 12 find the other​
    14·1 answer
  • Which statements about editing an existing Contact in Outlook are true? Check all that apply.
    9·2 answers
  • Which game would you play info you were competitive?
    13·2 answers
  • What is the most used gaming keyboard in 2022?
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!