Question
Write a program that creates a list of 20 integers (between 1 and 40) using a random number generator function. Write a function that returns the index (position) of the third largest element from the...
Write a program that creates a list of 20 integers (between 1 and 40) using a random number generator function. Write a function that returns the index (position) of the third largest element from the list of integers. If there are more than one third largest number, return the index of the first occurrence of that number.
Eg: Assume that your main function has created the following list of integers generated from the random number function.
[12, 30, 28, 4, 17, 21, 5, 3, 35, 33, 23, 25, 21, 14, 14, 33, 16, 38, 13, 29]
Expected output:
List of integers:
[12, 30, 28, 4, 17, 21, 5, 3, 35, 33, 23, 25, 21, 14, 14, 33, 16, 38, 13, 29]
Third largest number: 33
Index (position) of third largest number: 10
Answers
Main - JCreator File Edit View Project Build Run Tools Configure Window Help Sort,jav Main.javaX public class Main ( atatic void Print3Largest (int arrayl, int n) int firstmaxInteger.MIN VALUE: int secmax Integer MIN VALUE int thirdmaxInteger.MIN VALUE: for (int 1-0: 1 < n; i++) /Check if current element is less than firstmin, then update first, second and third/ if (arraylil >firstmax) thirdmaxsecmax: firatmaxarrayil: /* Check if current element is le53 than ecmin then update 3econd and third */ else if (arraylil > secmax) thirdmaxsecmax: ecmax arrayi: /* Check if current element is le53 than then update third/ else if (arrayti] > thirdmax) thirdmaxarrayil: System.out.println ("Third max-" thirdmax int y thirdmax for (int i-0:i<n:i+t For Help, press F1 Ln 8 Col 4 Char4 OVR Read CAPNUM 12:22 PM 10/05/2019Main - JCreator File Edit View Project Build Run Tools Configure Window Help Sort,jav Main.javaX else if (arrayi ecmax) thirdmaxsecmax: ecmax arrayi: /Check if current element is less than then update third/ else if (arrayti] > thirdmax) thirdmaxarrayil: System.out.println ("Third max-" thirdmax int y thirdmax for (int i-d:i<n:i+t) if (arraylil y Syatem.out.println ("Index of third max+(i+1)) break: Driver code public static void main (String args) int array(12,30,28, 4,17,21,5,3,35,33,23,25,21,14,14,33,16,38,13,29) int n array.length: Print3Largest (array, n) For Help, press F1 Ln 8 Col 4 Char4 OVR Read CAPNUM 12-22 PM H) 10/05/2019Main - JCreator File Edit View Project Build Run Tools Configure Window Help Sortjav Main.java*x public class Main ( atatic void Print3Largest (int arrayl, int n) int firstmaxInteger.MIN VALUE: int secmax Integer MIN VALUE int thirdmaxInteger.MIN VALUE: for (int 1-0: 1 < n; i++) /Check if current element is greater than firstmax, then update first, second and third/ if (arraylil >firstmax) thirdmaxsecmax: firatmaxarrayil: /Check if current element is greater than gecmax then update ฮีecond and third */ else if (arraylil > secmax) thirdmaxsecmax: ecmax arrayi: Check if current clement 1s greaterl than then update third/ else if (arrayti] > thirdmax) thirdmaxarrayil: System.out.println ("Third max-" thirdmax int y thirdmax for (int i-0:i<n:i+t For Help, press F1 Ln 36 Col55 Char 55 OVR Read CAPNUM 12:26 PM 10/05/2019Main - JCreator File Edit View Project Build Run Tools Configure Window Help Sortjav Main.java*x else if (arrayi ecmax) thirdmaxsecmax: ecmax arrayi: /Check if current element is greater than then update third/ else if (arrayti] > thirdmax) thirdmaxarrayil: System.out.println ("Third max-" thirdmax int y thirdmax for (int i-d:i<n:i+t) if (arraylil y Syatem.out.println ("Index of third max+(i+1)) break: Driver code public static void main (String args) int array(12,30,28, 4,17,21,5,3,35,33,23,25,21,14,14,33,16,38,13,29) int n array.length: Print3Largest (array, n) For Help, press F1 Ln 36 Col55 Char 55 OVR Read CAPNUM 12-26 PM H) 10/05/2019Main - JCreator File Edit View Project Build Run Tools Configure Window Help Sort,jav Main.javaX else if (arrayi ecmax) thirdmaxsecmax: ecmax arrayi: /Check if current element is less than then update third/ else if (arrayti] > thirdmax) thirdmaxarrayil: System.out.println ("Third max-" thirdmax int y thirdmax for (int i-d:i<n:i+t) if (arraylil y Syatem.out.println ("Index of third max+(i+1)) break: Driver code General Output Third max 33 Index of third max -10 Process completed Build Output General Output 12-22 PM ) 10/05/2019
Similar Solved Questions
1 answers
A survey about students government program at a school found that 120 students wanted an after school program and 240 students wanted durning school and 40 students wanted none, If a circle graph is made from this data, what would be the measure of the ce
a survey about students government program at a school found that 120 students wanted an after school program and 240 students wanted durning school and 40 students wanted none, If a circle graph is made from this data, what would be the measure of the central angle for the after school group...
1 answers
Javan Co has the following related to Class 8 assets: Beginning Balance: $40,000 Javan disposes of...
Javan Co has the following related to Class 8 assets: Beginning Balance: $40,000 Javan disposes of all assets within the class during the year, for proceeds of disposition of $20,000. If Javan Co has no additions for the year, and there are no assets remaining in t...
1 answers
For the problem we answer as if the Current date was January 1, 2018 LIABILITIES owed...
For the problem we answer as if the Current date was January 1, 2018 LIABILITIES owed of $ 60 All liabilities are community property debt. To whom Original Property Interes Current Paymen How Total # Date of Amount or Service t Rate Balancet often First Purchased (as of Amount paid Paymen Payment Ac...
1 answers
7. Silver ion forms a stable 1:1 complex with a chelating amine molecule. Calculate the silver...
7. Silver ion forms a stable 1:1 complex with a chelating amine molecule. Calculate the silver ion concentration at equilibrium when 25mL of 0.10 M silver nitrate is added to 50 mL of 0.15 Mamine. Given that Kf = 5.0 x 10'....
1 answers
DriveTrain, Inc. instituted a new process in October 2020. During October, 10,600 units were started in...
DriveTrain, Inc. instituted a new process in October 2020. During October, 10,600 units were started in Department A. Of the units started, 8,150 were transferred to Department B, and 2,450 remained in Work-in-Process at October 31, 2020. The Work-in-Process at October 31, 2020, was 100% complete as...
1 answers
OURCES CALCULATOR PULLSCREEN PRINTER V ON BACK The Blue Company issued $330.000 of 7 bonds on...
OURCES CALCULATOR PULLSCREEN PRINTER V ON BACK The Blue Company issued $330.000 of 7 bonds on January 1, 2017. The bonds are anuary 1 2022 w interest payable each and January 1. The bonds were sted at 101 Prepare the journal entries for (a) January 1 (1) July 1, and ) December 31. Assume The Company...
1 answers
In 2016, Natural Selection, a nationwide computer dating service, had $534 million of assets and $217...
In 2016, Natural Selection, a nationwide computer dating service, had $534 million of assets and $217 million of liabilities. Earnings before interest and taxes were $137 million, interest expense was $30 million, the tax rate was 40 percent, principal repayment requirements were $25.2 million, and ...
1 answers
Why do we use a simplified model of supply and demand when studying basic economics?
Why do we use a simplified model of supply and demand when studying basic economics?...
1 answers
1. In a transformation experiment, E. coli uptake pRGLO plasmids that carry GFP gene. The transformed...
1. In a transformation experiment, E. coli uptake pRGLO plasmids that carry GFP gene. The transformed bacterial cells are grown on an ampicillin-treated agar plate. Which of the following is considered as a vector? GFP gene C E. coli cell c ampicillin-treated agar plate 0.5 points QUESTION 2 1. What...
1 answers
A ) ( mean, proportion, standard deviance or variance ) B ) is n > 30...
a ) ( mean, proportion, standard deviance or variance ) B ) is n > 30 C ) determine the parameter to be tested D ) determine the test to be performed B ) Determine the parameter to be tested, and the test to be performed. Part: 0 / 6 Part 1 of 6 A simple random sample of size 13 has mean x = 9.4....
1 answers
24. (Correlation) A researcher wants to determine if there is a linear relationship between height and...
24. (Correlation) A researcher wants to determine if there is a linear relationship between height and weight. The following table represents the data collected. Display the data in a scatter plot on your calculator, draw a quick sketch below. Then find the linear regression and put the line of best...
1 answers
For the following chemical reaction HClO4(aq)+ NaOH(aq) H2O(l) + NaClO4(aq) write the net ionic equation, including...
For the following chemical reaction HClO4(aq)+ NaOH(aq) H2O(l) + NaClO4(aq) write the net ionic equation, including the phases. Which of these ions are considered ''spectator ions'' for this reaction? Check all that apply. H+ Na+ ClO4- OH-...
1 answers
Invest 1,000,000 Bank A : $1=€1 Bank B: $1.8=£1 Bank C: £1 =€1.5 How much can...
invest 1,000,000 Bank A : $1=€1 Bank B: $1.8=£1 Bank C: £1 =€1.5 How much can you make ?...
1 answers
The coefficient of linear expansion for some common materials are listed in the table to the...
The coefficient of linear expansion for some common materials are listed in the table to the right. You would like to design an emergency overheating alarm using one of these materials. In your design, at room temperature (23.0degreeC), a 5.51 cm long cylinder of the material will sit with one end a...
1 answers
EBook Problem Walk-Through Cost of Equity Radon Homes' current EPS is $7.90. It was $3,61 5...
eBook Problem Walk-Through Cost of Equity Radon Homes' current EPS is $7.90. It was $3,61 5 years ago. The company pays out 50% of its earnings as dividends, and the stock sells for $32. a. Calculate the historical growth rate in earnings. (Hint: This is a 5-year growth period.) Do not round int...
1 answers
7. Fredo, Inc., purchased 10 % of Sonny Enterprises for $1,000,000 on January 1, 2018. Sonny...
7. Fredo, Inc., purchased 10 % of Sonny Enterprises for $1,000,000 on January 1, 2018. Sonny recognized a total of $400,000 net income during 2018, paid $30,000 of dividends to Fredo during 2018, and at December 31, 2018, the market value of the Sonny investment increased to $1,040,000. Required: Pr...
1 answers
1-at what times are cars at the same point? 2-At what times is the distance from...
1-at what times are cars at the same point? 2-At what times is the distance from A to B neither increasing nor decreasing ? 3-at what times do A and B have the same acceleration? Constants Two cars, A and B, travel in a straight line. The distance of A from the starting point is given as a funct...
1 answers
USE C++ Problem 3: Prompt the user to enter a whole number of points to be...
USE C++ Problem 3: Prompt the user to enter a whole number of points to be used in the approximation and robustly confirm that the number of points is positive (remember always ask user to re-enter before any calculations are performed). Then calculate and output the approximation for pi. Run your p...