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
GrogVix [38]
3 years ago
5

Write a program that reads a list of integers, and outputs the two smallest integers in the list, in ascending 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 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:
larisa [96]3 years ago
5 0

Answer:

Following are the code to this question:

import java.util.*;//import package

public class Main //defining a Main class  

{

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

   {

       Scanner oxc = new Scanner(System.in);//defining main method  

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

       n= oxc.nextInt();//input value from user end  

       m1 = oxc.nextInt(); //input value from user end

       m2 = oxc.nextInt(); //input value from user end

       if (m1 > m2)//defining if block that check m1 greater then m2  

       {

           //swapping the value

           t= m1;

           m1 = m2;

           m2 = t;

       }

       for (i=2;i<n;i++)//defining for loop that check the smallest value    

       {

           num = oxc.nextInt();//input value from user end

           if (num < m1) //defining if block that check num lessthan m1

           {

               m2 = m1;//store m1 value into m2  

               m1 = num;//store num value into m1

           }

           else if (num<m2)//defining else if block that check num lessthan m2

           {

               m2 = num;//store m2 value in num

           }

       }

       System.out.println(m1 + " " + m2);//print value

   }

}

Output:

5

10

5

3

21

2

2 3

Explanation:

In the above-given code, inside the main class the main method is declared, in method 6 integer variable "n,m1,m2, num,t, and i" is declared, and in the "n, m1, m2, and num" is used for input the value from the user end.

  • In the next step, and if block is defined that check m1 greater than m2, and swap the value.
  • In the next step for loop s used that defines two conditions that check the two smallest value from the user input and print its value.
You might be interested in
Select each item that represents what the Internet may be used for:
VLD [36.1K]
You're right! You can do all of these on the internet. 
3 0
3 years ago
D-H public key exchange Please calculate the key for both Alice and Bob.
Nesterboy [21]

Answer:

See explaination

Explanation:

Please kindly check attachment for the step by step solution of the given problem.

6 0
4 years ago
Question 1 of 10
Basile [38]

Answer:

A, C, and D I believe.

Explanation:

I'm in the same class as you lol

6 0
2 years ago
Differentiate between data and information ​
Mademuasel [1]
Data is an individual unit that contains raw materials which do not carry any specific meaning. information is a group of data that carries logical meaning. info depends on data.
5 0
3 years ago
Dress4Win has asked you to recommend machine types they should deploy their application servers to.
tensa zangetsu [6.8K]

Answer:

Option A is the correct option.

Explanation:

Because Dress4Win is the online web organization that asked to the consultant to advice that type of machines that they want to expand their server for those application which perform the work of the mapping on the basis of the premises physical hardware cores and also in the clouds softwares that is nearest machines types of RAM.

7 0
3 years ago
Other questions:
  • What is the size of the opening in the camera that the light passes through?
    9·2 answers
  • (Game Design) Which of the following is NOT a name of a popular digital sculpting application?
    13·1 answer
  • Write calls to printf to display the variable x in the following formats:
    8·1 answer
  • SONET: is a standard for optical transmission that currently operates at Terabit per second speeds is almost identical to the IT
    7·1 answer
  • In 1997, microsoft was accused of using a monopoly in operating systems to control the market for _____.
    8·2 answers
  • Which marketing claim do you see on the opening screen of the new words with friends
    14·1 answer
  • By
    7·1 answer
  • The objective of this task is to use Scapy to estimate the distance, in terms of number of routers, between your VM and a select
    10·1 answer
  • Cuales son las intenciones de la tecnología para el desarrollo social y calidad de vida
    10·1 answer
  • Chantal has configured the network at her company's new headquarters with a number of VLANs. All devices joined to the individua
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!