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
What is the exact number of bytes in system of memory that contains (a) 64K bytes (In Binary)(b) 32M bytes
VashaNatasha [74]

Answer:

64 K bytes = 65536 bytes

32 M bytes = 33554432 bytes

Explanation:

The question expect the number of bytes in binary instead of decimal. So this is important to understand that:

  • 1K bytes = 1024 bytes (in binary)

Therefore,

  • 64 Kb = 64 x 1024 =  65536 bytes

Using the similar calculation logic, we know

  • 1M bytes = 1024 x 1024 = 1048576 bytes (in binary)

Therefore,

  • 32 M bytes = 32 x 1048576 =  33554432 bytes
5 0
3 years ago
Which website is important for hacking
Yuliya22 [10]

Answer:

Here's a few

Explanation:

  • SQL Injection attacks. SQL Injection attack is the most common website hacking technique. ...
  • Cross Site Scripting (XSS) ...
  • Denial of Service (DoS/DDoS) ...
  • Cross-site request forgery (CSRF or XSRF) ...
  • DNS Spoofing (DNS cache poisoning) ...
  • Social engineering techniques.

Glad I could help!!

6 0
2 years ago
when using screwdrivers you should always be aware that the screwdriver blade might slip out of the slot and strike you in the .
ELEN [110]

When using screwdrivers you should always be aware that the screwdriver blade might slip out of the slot and strike you in the:

  • -hand
  • -eye
  • -mouth

<h3>What is a Screwdriver?</h3>

A screwdriver is said to be a kind of a modern tool that can come in a manual or powered type and it is one that is often used for turning screws.

Note that a typical simple screwdriver is one that has a handle as well as a shaft and it is also one that is often ending in a tip where a given user can be able to put their hands into the screw head before turning the handle.

Therefore, when using screwdrivers you should always be aware that the screwdriver blade might slip out of the slot and strike you in the:

  • -hand
  • -eye
  • -mouth

Learn more about screwdrivers  from

brainly.com/question/20717091

#SPJ4

3 0
10 months ago
A lost update occurs when
shutvik [7]

Answer:

Option A is the correct answer.

Explanation:

7 0
3 years ago
At the end of the day, you finish a job only to find that the user you were doing it for had to leave. What should you do
Vika [28.1K]

The way to proceed in the situation presented would be:

  • Finish the process started to help that user and continue with the other tasks of the day.

<h3>How to serve a customer properly?</h3>

In different work positions we have the possibility of personally or virtually assisting clients by carrying out procedures to help them improve their service or experience with the company.

Companies have developed complete customer service systems so that their employees know how to proceed in different specific situations in which their customers require help.

In the situation described, the most appropriate thing would be to finish the process required by the user and continue with the other tasks of the day that were planned.

Learn more about job in: brainly.com/question/2018598

7 0
1 year ago
Other questions:
  • What device brocasts all data packets to other nodes on a network?
    5·1 answer
  • Raeball was a lovin doll. And she spoke her mind as she stood tall. She made you special and loved. You're missed by so many. An
    10·2 answers
  • Write a function that takes an array of integers and its size as parameters and prints the two largest values in the array. In t
    5·1 answer
  • Is Digital technology always better or should we champion or even return to innovative of analog machines and experiences? Apex
    13·1 answer
  • 1. Do you consider Facebook, MySpace, and LinkedIn forms of disruptive or sustaining technology? Why?
    15·1 answer
  • In this part, you have to implement a linked list that maintains a list of integers in sorted order. Thus, if the list contains
    13·1 answer
  • The correct ordering of the seven layers from "top" to "bottom" is
    11·1 answer
  • Write a program to read a list of exam scores given as integer percentages in the range 0-100. Display the total number of grade
    10·1 answer
  • What is cyber ethics​
    10·2 answers
  • Do you think Mortal Combat is cool?
    10·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!