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
An image is 160x 42 what is this a measure of?
mixas84 [53]
This would be a measure of Resolution. Image size is the general version of Resolution as Resolution is the measurement use FOR image size.
8 0
3 years ago
The RAM memory of a computer contains the volatile memory, which includes
lara31 [8.8K]

The RAM memory of a computer contains the volatile memory, which includes; Websites recently visited

<h3>Random Access Memory(RAM)</h3>

Random access memory (RAM) is defined as a computer's short-term memory that it utilizes to handle all active tasks and applications.

Now, no single program, file, game, or stream would work without a RAM. Thus, RAM is a temporary storage that goes away when we shut down the computer.

Examples of things that RAM store from the options given is only websites visited recently.

Read more about Random Access Memory at; brainly.com/question/86807

3 0
2 years ago
Dns (domain name system) servers translate all domain names into _____. hypermedia cookies ip addresses proxy servers
sweet-ann [11.9K]
<span>Dns (domain name system) servers translate all domain names into </span>ip addresses
4 0
3 years ago
And Python code for the following programming problem and the pseudo code below
lora16 [44]

Answer:

endProgram = "no"

endOrder = "no"

totalBurger = 0

totalFry = 0

totalSoda = 0

total = 0

tax = 0

subtotal = 0

option = 0

burgerCount = 0

fryCount = 0

sodaCount = 0

def resetVariables():

    #reset variables

   totalBurger = 0

   totalFry = 0

   totalSoda = 0

   total = 0

   tax = 0

   subtotal = 0

def getBurger():

   global burgerCount

   burgerCount += int(input("Enter the number of burgers you want: "))

   totalBurger =burgerCount * .99

   return totalBurger

def getFry():

   global fryCount

   fryCount += int(input("Enter the number of fries you want: "))

   global totalFry

   totalFry +=fryCount * .79

   return totalFry

def getSoda():

   global sodaCount

   sodaCount += int(input("Enter the number of sodas you want: "))

   global totalSoda

   totalSoda +=sodaCount * 1.09

   return totalSoda

def calcTotal():

   global subtotal

   subtotal += totalBurger + totalFry + totalSoda

   global tax

   tax += subtotal * .06

   global total

   total += subtotal + tax

   return total

def printReceipt(total):

   print("Your total is $",round(total, 2))

#Loop to run program again

while endProgram == "no":

   resetVariables()

   #Loop to take in order

   while endOrder == "no":

       print("Enter 1 for Yum Yum Burge\nEnter 2 for Grease Yum Fries\nEnter 3 for Soda Yum: \n")

       option = int(input("Enter option: "))

       if option == 1:

           bugertotal = getBurger()

       elif option == 2:

           frytotal = getFry()

       elif option == 3:

           sodatotal = getSoda()

       endOrder = input("Do you want to end your order? (Enter no to add more items): ")

       mytotal = calcTotal()

       printReceipt(mytotal)

   endProgram = input("Do you want to end the program? (Enter no to process a new order): ")

Explanation:

The python source code displays the menu of a restaurant and the prices of each meal. The module takes multiple orders, calculates and displays the total bill of the order with tax included.

6 0
2 years ago
Whose task it is to ensure that the product flows logically from one step to another?
AleksAgata [21]
UX i believe. Web designer and graphic designer are visual which is the basis of UI. Think of UX as User eXperience and in order to have a good experience it has to flow. If it can flow then u can design it. Think of UX as the skeleton and UI is the flesh
3 0
3 years ago
Other questions:
  • List of programming languages and their typing
    5·2 answers
  • What is the decimal equivalent of (11000 + 10000)/101?
    10·1 answer
  • What does nat stand for? network access trigger network administration timetable network address translation network association
    13·1 answer
  • A technician wants to consolidate and log specific alerts from network devices into a database so maintenance tasks and potentia
    11·1 answer
  • Which command can be used to find errors on a hard drive​
    6·1 answer
  • 22. A<br> allows one computer to input data into another computer.
    6·1 answer
  • What types of tools are used in the process of a digital or network investigation?
    12·1 answer
  • A customer seeks to buy a new computer for private use at home. The customer primarily needs the computer to use the Microsoft P
    9·1 answer
  • A developer designed a process in UiPath Studio that is best-suited for a simple and linear process. Which Studio workflow type
    7·1 answer
  • 2. Why do old video games have large pixels and images with jagged edges?
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!