Question: 1. Develop algorithms for the following Java programs. Once the algorithms are documented, you will then write the code. 2. There is a famous

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.
Step by Step Solution
3.32 Rating (164 Votes )
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
