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
Explain what will happen if we continue to use fossil fuels at the rate we are now and what impacts it will have on the planet.
Westkost [7]

Answer:

At the point when non-renewable energy sources are singed, they discharge carbon dioxide and other ozone depleting substances, which thusly trap heat in our air, making them the essential supporters of an Earth-wide temperature boost and environmental change. At the point when we consume oil, coal, and gas, we don't simply meet our vitality needs—we drive the current an unnatural weather change emergency also. Non-renewable energy sources produce huge amounts of carbon dioxide when consumed. Carbon discharges trap heat in the air and lead to environmental change.

7 0
3 years ago
Comments should
suter [353]

Answer:

Correct answer is:

communicate the purpose of the code that follows it.

Explanation:

Let have a look at each option

comment should give the reader the background of the programmer.

Comments are unable to do so.

Be written on every line

No, it is not need as comment are useful only to explain difficult or complex part of code.

communicate the purpose of the code that follows it.

yes, this option is true, as comments will give hints to programmer about the piece of code.

give information about how many hours it took to write the code

No, comments can answer it,

3 0
2 years ago
Read 2 more answers
An employee at a branch office is creating a quote for a customer. In order to do this, the employee needs to access confidentia
SOVA2 [1]

The employee would access an intranet to maintain security.

6 0
3 years ago
By default, the document has a (blank) margin on all four sides
Brut [27]
The normal margin is 1 inch on all sides
6 0
2 years ago
Read 2 more answers
Browsers often store the cookies in individual files, each named for the server that owns the cookie. Whenever the browser visit
Anna11 [10]

Answer:

The answer is TRUE.

Explanation:

Cookies in browsers are like identification criteria. It contains unique data to a specific user. The use of this is to ensure that servers or websites that you have visited previously will recognize you as the same user who has been there before. This will cause the data and website information to load faster that before.  

Think of it as your school's gate. The security guard is the browser. He will let you inside the campus without question since he has seen your school ID or has recognize you as a student of the school.  

Cookies come in various types such as:

  • Authentication cookies - most common type of cookies that websites used to recognize you as the user who has been there or logged in before.
  • Persistent cookies - cookies that can be used for long term. Sometimes, you will encounter websites that allows the user to remember his log in credentials, this is the type of cookies that these websites used. Often, these cookies are willingly enabled by users.
  • Session cookies - cookies with expiration or being stored temporarily. These cookies will be terminated once the browser is closed.
  • Third-party cookies - These are additional cookies being added by the website you are using. But these cookies are not owned by the website itself, but is being used by other websites to track down your activities to make you see and experience advertisements that are catered to you. These are mostly exposing threats.
8 0
3 years ago
Read 2 more answers
Other questions:
  • A misfire code is a type _______ diagnostic trouble code (DTC).
    5·1 answer
  • Consider the following method:
    8·2 answers
  • Create a program that prints out a list of all the divisors of a number stored in a variable. (If you don’t know what a divisor
    11·1 answer
  • Complete the body of the decrement static method using only the NaturalNumberKernel methods (multiplyBy10, divideBy10, and isZer
    10·1 answer
  • To have a reason or purpose to do something
    8·2 answers
  • In addition to assuming that n is a power of 2, we made, for the sake of simplicity, another, more subtle, assumption in setting
    5·1 answer
  • Look at (c), is it accurate? ​
    9·2 answers
  • Documental acerca de los principales materiales que se emplean en la fabricación de medios técnicos utilizados en una oficina.
    9·1 answer
  • How would a barcode reader be used in a healthcare industry?​
    6·1 answer
  • Advantages of monolithic operating system? ​
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!