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
There is no way to track your smartphone once you lost it, true or false?
Ymorist [56]
If you originally had a tracking device installed on a different device like find my iPhone, you can easily see where it is. If your phone is Android, Google has a system where you can search where's my phone, and if you have your email login into your phone, you can log in on Google and Google will show you where it is. 
6 0
3 years ago
Read 2 more answers
Which of the following websites is least biased
labwork [276]
I think it's D because it's made out of facts. The other ones are more likely to include bias.
8 0
3 years ago
On a leading-trailing system technician A says that both shoes do equal work when stopping while going in reverse. Technician B
sleet_krkn [62]

Based on the scenario above about the leading-trailing system Both technician A and B are incorrect.

<h3>How many brake shoes function?</h3>

There are known to be two shoes function that are said to be working a way where both become either the trailing shoe or leading shoe based on whether the vehicle is moving forward or backward.

Therefore we can say that, Based on the scenario above about the leading-trailing system Both technician A and B are incorrect.

Learn more about trailing system from

brainly.com/question/14367881

#SPJ1

5 0
1 year ago
Big Data, Apple Pie, and the Future In this unit, you were introduced to various kinds of software, particularly databases. Data
Andreas93 [3]

Answer:

I want to answer the 1st question. It asks, “Will we treat people unfairly for crimes they haven’t committed?” Well, of course, that’s a 100% chance. But, some people forget that people treat people unfairly for crimes they haven’t committed. Some people stay in jail for up to 35 years and are then released because they are innocent. Yes, computers will make mistakes, but the probability is much, much smaller than a human.

Explanation:

3 0
2 years ago
Which site had a major influence on the social gaming site Friendster?
Oduvanchick [21]
The answer is, "Ryze".
4 0
3 years ago
Read 2 more answers
Other questions:
  • Jason is creating a web page for his school's basketball team. He just finished creating his storyboard. Which tool should he us
    7·1 answer
  • Which two software interfaces allow adjustment of the cpu voltage? (choose two.)?
    10·1 answer
  • How much space should be allotted to park your vehicle parallel to the curb?
    5·1 answer
  • I'm 11, except my profile says I'm 15.
    15·1 answer
  • Using a personal computer to produce high quality printed documents.
    10·1 answer
  • Please help, Tech class!!
    14·1 answer
  • What is the best motivation that you can do/give to make your employees stay? ​
    6·1 answer
  • Assignment 3: chabot<br>​
    13·1 answer
  • People’s personal information is collected _____. Select 4 options.
    7·2 answers
  • If two devices simultaneously transmit data on an Ethernet network and a collision occurs, what does each station do in an attem
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!