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.