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
How do films use camera shots?
lorasvet [3.4K]
These advanced camera shots, or angles, are used in film to convey an effect or emotion rather than exemplify a sense of space. Before filming, cinematographers will write out their shot list in order to plan how each scene of their film should be shot
7 0
3 years ago
Read 2 more answers
Which is true about routers and switches?
Julli [10]

Answer:

Routers control traffic between networks while switches control traffic within a network

Explanation:

There are different devices involves in computer networking. These devices include hub, switch, router and other components.

Switch is used to connect the computer with in the network. It controls the traffic between different computers within the network. Different computers are connected with each other through different cables with the help of switch.

On the other hand, different LAN's connected through the cable with a router to communicate with each other. This device is used to control the traffic between different networks.

 

8 0
3 years ago
Digital data is _____ and analog information is _____.
Liula [17]
Digital data is discrete and analog information is continuous.
6 0
4 years ago
What are three examples of information technologies you use in your everyday life? Which do you consider to be the most importan
Anit [1.1K]
I think there's so many example of information technology in our daily life.

The word information and technology which means all of information that is provided by technology.

Every day we use information technology such as social media, television, computer, and etc.

I think this brainly platform is also information technology.

Which can provide so much necessary information to the whole world
3 0
3 years ago
100 points please hurry!!!
attashe74 [19]

The screenshot required is not visible

3 0
4 years ago
Read 2 more answers
Other questions:
  • Susie works for an architectural firm and the partners have always drawn the plans for projects by hand. Though Susie learned ho
    8·1 answer
  • How secure is a password protected word document?
    10·1 answer
  • List three components of a computer system​
    10·1 answer
  • How many bits must be “flipped” (i.e., changed from 0 to 1 or from 1 to 0) in order to capitalize a lowercase ‘a’ that’s represe
    7·1 answer
  • The ____ is the point in the past to which the recovered applications and data at the alternate infrastructure will be restored.
    15·1 answer
  • Write a program that accepts an integer value called multiplier as user input. Create an array of integers with ARRAY_SIZE eleme
    7·1 answer
  • In<br>6) which device can not be shared<br>network?​
    11·1 answer
  • Give two reasons why it is not advisable to open email from unknown sources​
    13·2 answers
  • Which document outlines the activities carried out during testing?
    9·1 answer
  • Integrated circuits incorporate many transistors and electronic circuits on a single tiny silicon chip, allowing ____ to be even
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!