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
What are your initial thoughts regarding copyright and fair use after watching the clip?
Elanso [62]
The answer is A you’re welcome
5 0
3 years ago
In a batch operating system, three jobs are submitted for execution. Each job involves an I/O activity, CPU time and another I/O
Ilia_Sergeevich [38]

Answer:

a) CPU utilization for uniprogramming system = 18.2%

b) CPU utilization for multiprogramming system = 41.379%

Explanation:

IO time = total time – CPU time

For JOB 1  

CPU time = 3ms ,

total time= 23ms

IO time = 23-3 = 20ms ,

For JOB 2

CPU time =5ms

total = 29ms

IO time = 29-5 = 24ms  

For JOB 3  

CPU time = 4ms

total = 14ms

IO time = 14-10 =10ms  

1.) In uniprogramming system, operations are performed sequentially

CPU utilization=total CPU time / total real time

CPU utilization =(3+5+4) / (23+29+14)

CPU utilization =0.182 or 18.2%

2) In multiprogramming system, jobs wait for the CPU to get free while performing IO operations concurrently

steps followed by the os

1. IO for 1st job                           at 0ms

2. IO for 2nd job                          at 0ms

3. IO for 3rd job                          at 0ms

4. CPU time for 3rd job              at 5ms

5. Next IO job for 3rd job           at 9ms END at 14ms

6. CPU time for 1st job              at 9ms

7. Next IO job for 1st job           at 14ms END at 23ms

8. CPU time for 2nd job             at 14ms

9. Next IO job for 2nd job          at 15ms END at 29ms

CPU time is 3+5+4 =12ms

Total execution time = 29ms

CPU utilization = 12*100/29= 41.379%

5 0
2 years ago
Computer that process digital as well as analogue signals​
Nuetrik [128]

Answer:

The answer is hybrid computer coz it is the combination of both analog and digital computers

Explanation:

hope it helps

good day

5 0
3 years ago
Identify the menu under which you'll find the Header and Footer option.
Genrish500 [490]

The answer is B. View.

4 0
3 years ago
Which network type uses a coaxial cable to receive its signal?.
Tresset [83]
If you’re asking what I think your saying I know comcast does
6 0
2 years ago
Other questions:
  • Which of the following STEM discoverers developed a new type of computer hardware?
    11·1 answer
  • As the operations manager for a supermarket chain, Mai needs to find a telecommunications technology that: enables managers in r
    9·1 answer
  • A potential threat to administrators’ ability to manage the correctional system is
    12·1 answer
  • What is the name of the program file that you can enter in the Windows search or Run box to execute Event Viewer? What process i
    12·1 answer
  • William wants to create a document using a DTP<br> what time saving techniques can he use?
    9·1 answer
  • Click on the _____ tab on the ribbon to open the backstage view.
    7·1 answer
  • Design and implement an application that plays the Hi-Lo guessing game with numbers. The program should pick a random number bet
    13·1 answer
  • When reading words using a Scanner object's next method, _________. a. any characters at the beginning of the input that are con
    5·1 answer
  • True and False(Total points: 10)
    12·2 answers
  • HELPPPP MEEEE!!!!! ITS LIFE OR MUERTEEE
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!