1. Develop algorithms for the following Java programs. Once the algorithms are documented, you will then...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
1. Develop algorithms for the following Java programs. Once the algorithms are documented, you will then write the code. 2. There is a famous story about a primary school teacher who wanted to occupy his students' time by making the children compute the sum of 1+2+3+100 by hand. As the story goes, the teacher was astounded when one of the children immediately produced the correct answer: 5050. The student, a child prodigy, was Carl Gauss, who grew up to be one of the most famous mathematicians of the eighteenth century. Write a program called Count Loop.java that contains a main method with a loop that will compute and print the sum of all the integers between 1 and 100, inclusive. Execute your program to verify that the output is correct. 3. After you have the program working, refactor, change the code, it so you can compute 1 + 2 + ... +n where n is any positive integer. In other words, your revised program should prompt the user to enter a number, read the user input, calculate the sum of the integers from 1 to the input value, and output the sum. 4. Java provides three types of loops: while, for, and do while. Theoretically, they are interchangeable- any program you write with one kind of loop could be rewritten using any of the other types of loops. As a practical matter, though, it is often the case that choosing the right kind of loop will make your code easier to produce, debug, and read. It takes time and experience to leam to make the best loop choice, so this is an exercise to give you some of that experience. Rework the Count Loop.java program so that you have three different versions of the loop: a while loop, a for loop, and a do while loop. Please note that your program should ask for user input only once, and it should use the same user input for all three loops. You will output the results from each loop, so you will have three outputs, one from each type of loop. Save and run the CountLoop.java program showing the three results, one for each loop in the program. Take a screenshot of this code running. 5. Some computations require multiple loops where the "inner" loop is code nested inside the body of the "outer" loop code. Suppose we want to produce the following output using a nested looping control structure that outputs a single character each time through the inner loop: 44444 The outer loop will manage the rows and the inner loop will count the number of *** characters to be displayed on that row. Write a program called Nested LoopTriangle.java containing the code that will produce the output described above using nested loops. 6. Once you've got the right triangle to display correctly, add another set of loops to produce a second triangle that looks like the triangle below. Hint: You will need a third nested loop that will increase the spaces as the number of asterisks decreases. NOTE: When finished, Nested LoopTriangle.java should print out both Triangles. 7. Save and run the Nested LoopTriangle.java program showing the two triangles. Take a screenshot of this code running. 8. Submit your completed CountLoop.java and Nested LoopTriangle.java files along with the two screenshots to the submission area in Canvas. 1. Develop algorithms for the following Java programs. Once the algorithms are documented, you will then write the code. 2. There is a famous story about a primary school teacher who wanted to occupy his students' time by making the children compute the sum of 1+2+3+100 by hand. As the story goes, the teacher was astounded when one of the children immediately produced the correct answer: 5050. The student, a child prodigy, was Carl Gauss, who grew up to be one of the most famous mathematicians of the eighteenth century. Write a program called Count Loop.java that contains a main method with a loop that will compute and print the sum of all the integers between 1 and 100, inclusive. Execute your program to verify that the output is correct. 3. After you have the program working, refactor, change the code, it so you can compute 1 + 2 + ... +n where n is any positive integer. In other words, your revised program should prompt the user to enter a number, read the user input, calculate the sum of the integers from 1 to the input value, and output the sum. 4. Java provides three types of loops: while, for, and do while. Theoretically, they are interchangeable- any program you write with one kind of loop could be rewritten using any of the other types of loops. As a practical matter, though, it is often the case that choosing the right kind of loop will make your code easier to produce, debug, and read. It takes time and experience to leam to make the best loop choice, so this is an exercise to give you some of that experience. Rework the Count Loop.java program so that you have three different versions of the loop: a while loop, a for loop, and a do while loop. Please note that your program should ask for user input only once, and it should use the same user input for all three loops. You will output the results from each loop, so you will have three outputs, one from each type of loop. Save and run the CountLoop.java program showing the three results, one for each loop in the program. Take a screenshot of this code running. 5. Some computations require multiple loops where the "inner" loop is code nested inside the body of the "outer" loop code. Suppose we want to produce the following output using a nested looping control structure that outputs a single character each time through the inner loop: 44444 The outer loop will manage the rows and the inner loop will count the number of *** characters to be displayed on that row. Write a program called Nested LoopTriangle.java containing the code that will produce the output described above using nested loops. 6. Once you've got the right triangle to display correctly, add another set of loops to produce a second triangle that looks like the triangle below. Hint: You will need a third nested loop that will increase the spaces as the number of asterisks decreases. NOTE: When finished, Nested LoopTriangle.java should print out both Triangles. 7. Save and run the Nested LoopTriangle.java program showing the two triangles. Take a screenshot of this code running. 8. Submit your completed CountLoop.java and Nested LoopTriangle.java files along with the two screenshots to the submission area in Canvas.
Expert Answer:
Answer rating: 100% (QA)
To summarize the tasks Write a Java program called CountLoopjava that computes and prints the sum of ... View the full answer
Related Book For
Government and Not for Profit Accounting Concepts and Practices
ISBN: 978-1118155974
6th edition
Authors: Michael H. Granof, Saleha B. Khumawala
Posted Date:
Students also viewed these programming questions
-
Design a Java class that represents a cache with a fixed size. It should support operations like add, retrieve, and remove, and it should evict the least recently used item when it reaches capacity.
-
can someone solve this Modern workstations typically have memory systems that incorporate two or three levels of caching. Explain why they are designed like this. [4 marks] In order to investigate...
-
Case 2: First Year on the Job Joe finally received that job offer in the mail. He worked part-time for First Cirrus Bank during the spring semester and the work experience had paid off. Beginning on...
-
What do you personally believe about the value of the WTO? Explain why you feel the way you do.
-
Evaluate the definite integral using the values below. -6 "6 [~ dx = 320, [x dx = 16, [*dx = 4 2 2
-
Many researchers are interested in the transcription of protein-encoding genes in eukaryotes. Such researchers want to study mRNA. One method that is used to isolate mRNA is column chromatography....
-
Harrelson Company manufactures pizza sauce through two production departments: Cooking and Canning. In each process, materials and conversion costs are incurred evenly throughout the process. For the...
-
1. A hollow conducting sphere has an inner and outer radius of R and R2 respectively. A point charge of +Q sits inside the hollow sphere at the center. Additionally, a charge of +2Q is distributed...
-
A missile guidance system has five fail-safe components. The probability of each failing is 0.05. Find these probabilities. a. Exactly 2 will fail. b. More than 2 will fail. c. All will fail. d....
-
Financial analysts forecast Best Buy Company (BBY) growth for the future to be 17.00 percent. Their recent dividend was $2.29. What is the value of their stock when the required rate of return is...
-
There's always a cost to any benefit being provided. A subsidy comes with a cost as it has to receive funding from its citizens. An increase of subsidies across the nation, the more money it will be...
-
Select five of your favorite sport venues, and trace the history of the naming rights for that venue (i.e., length and dollar amount of the contract). Has the value of these naming rights deals...
-
Select one of the exhibition images of The Family of Man found here, Explain in your words why this photograph stood out to you from the 90 images, and what does it feature about photography's history
-
what will happen to the firm When the production is inefficient ? is it directly affect the firm resources .give explanation ?
-
Select and describe a specific division of a larger healthcare organization, such as an emergency department, a surgical service, or a physician practice. Locate at least three recent (within the...
-
IHN, then (1 +i V3y + (1-iV3" is equal to: Select one a. 1NT 2+1 sin 3 b. None of these C. 2n+1 cos 3. d. 2" sin 2
-
Bobbie Singh provides writing services for small businesses. He blogs for companies that need professionally written content. His business records at November 15, 2023, are shown below: During the...
-
Select the best answer. 1. Which of the following should not be included in the introductory section of a city's CAFR? a. Management's discussion and analysis b. Letter of transmittal c. Government...
-
The bylaws of the Wells City Downtown Development Authority state that of the seven members of its governing board, two must be members of the Wells City Council, one must be a member of the City...
-
In 2015, the Rubin Center for the Arts received a $2 million endowment, the income of which was to be used to support local artists. The center invested the proceeds in securities. In 2015, owing to...
-
Show that if a liquid is in equilibrium with its own vapour and an inert gas in a closed vessel, then \[\frac{\mathrm{d} p_{v}}{\mathrm{~d} p}=\frac{ho_{v}}{ho_{l}}\] where \(p_{v}\) is the partial...
-
a. Describe the meaning of the term thermodynamic equilibrium. Explain how entropy can be used as a measure of equilibrium and also how other properties can be developed which can be used to assess...
-
Show that when different phases are in equilibrium the specific Gibbs energy of each phase is equal. Using the following data, show the pressure at which graphite and diamond are in equilibrium at a...
Study smarter with the SolutionInn App