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
olga55 [171]
3 years ago
6

java Two smallest numbers Write a program that reads a list of integers, and outputs the two smallest integers in the list, in a

scending order. The input begins with an integer indicating the number of integers that follow. You can assume that the list will have at least 2 integers and fewer than 20 integers. Ex: If the input is: 5 10 5 3 21 2 the output is: 2 and 3 To achieve the above, first read the integers into an array. Hint: Make sure to initialize the second smallest and smallest integers properly.
Computers and Technology
1 answer:
SashulF [63]3 years ago
7 0

Answer:

The code to this question can be defined as follows:

import java.util.*;//import package for user input

public class Main //defining a class

{

public static void main(String[] args)//defining main method  

{

   int m1,m2,num,t,i;//defining integer variable

   Scanner incx = new Scanner(System.in);//creating Scanner class object

   m1 = incx.nextInt();//input value

   m2 = incx.nextInt();//input value  

   if (m1 > m2)//use if block to check m1 greater than m2  

   {//swapping value

       t = m1;//holding m1 value in t

       m1 = m2;//defining m1 that take m2

       m2 = t;//holding m2 value  

   }

   for (i = 2; i < 6; i++)//defining for loop  

   {

       num = incx.nextInt();//input value  

       if (num < m1) //defining if block to smallest value

       {

           m2 = m1;//holding m2 value in m1

           m1 = num;//holding num value in m1

       }  

       else if (num < m2)//defining if block to smallest value  

       {

           m2 = num;//holding num value in m2

       }

   }

       System.out.println(m1 + " " + m2);//print two smallest values

   }

}

Output:

5

10

5

3

21

2

2 3

Explanation:

In the above code, five integer variable "m1, m2, num, t, and i" is declared, in which it creates the scanner class object for inputs the value and use m1 and m2 use to the input value.

In the next step, if a block is used to swap the value and pass into the for loop that use if block to find the two smallest values and hold its value into the m1 and m2 and print its value.

You might be interested in
To order the records in the answer to a query in a particular way, you ____ the records.
Alex_Xolod [135]
To order the records in the answer to a query in a particular way, you "Sort" the records. Sorting the records will allow the user to sort the sequence of the records based on his or her preferences, he or she may sort it ascending or descending.<span />
8 0
2 years ago
Which is the correct formula to add the values in cells A1 and B1? A. SUM(A1+B1) B. =SUM(A1+B1) C. =SUMA1+B1 D. A1+B1
galina1969 [7]
D I'd the answer to the problem
4 0
3 years ago
Read 2 more answers
2. What does the Action tool allow you to do in Microsoft PowerPoint? (20 points)
creativ13 [48]
B. Add actions

A. a presentation without a clear beginign middle and end

A. add action between slides
7 0
3 years ago
Read 2 more answers
A​ _______ helps us understand the nature of the distribution of a data set.
Sphinxa [80]

Frequency distribution
3 0
3 years ago
An archive of files that usually contain scripts that install the software contents to the correct location on the system is ref
Anika [276]

Answer:

Option 3 is the correct answer for the above question.

Explanation:

  • A tarball is a software which is used to encrypt the other software or hide the other software and make it small. It again makes the original software program from the encrypted ones.
  • It is used to make the file sort and can use for the transfer which takes some amount of memory.
  • The above question asked about that technology which is used to make encrypted software from the original software and use it with the help of some script. Then the answer is tarball which is referred to from option 3. Hence Option 3 is the correct answer for the above question while the other is not because--
  • Option 1 states about the package manager which is used to manage the library only.
  • Option 2 states about the DBMS which is used to manage the database.
  • Option 4 states about the router which is used for the internet.

8 0
3 years ago
Other questions:
  • How to open CD port in PC lenovo ideapad 330​
    14·1 answer
  • What is the purpose of the “little down arrow” next to many different functions in word
    6·1 answer
  • In the year of our Lord 66, the Emperor Nero, being at that time in the twenty-ninth year of his life and the thirteenth of his
    10·1 answer
  • Enhancing and optimizing customer retention and loyalty is a major business strategy.
    15·1 answer
  • A __________ network is good for connecting computers over boundaries.
    6·2 answers
  • --------------------is a host that runs software to provide information, such as web content, to other hosts.
    9·1 answer
  • Charles would like to move his internet browser window so that he can see his desktop.He should
    5·1 answer
  • Which part(s) of CAIN is realized through the use of message digest functions and hashes?
    14·1 answer
  • What is online school like 6 sentences
    12·1 answer
  • The goal of this problem is to cover all roads with cameras. A camera placed at a station can cover all the roads connected to i
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!