Lab 4: Loops
Your task is to complete three problems on loops. Upload each of the files as a different program.1 Assignment 1Write a program that asks the user to enter the size of a triangle (an integer from 1 to 50). Display the triangle by writing lines of asterisks. The rest line will have one asterisk, the next will have two, and so on, with each linehaving one more asterisk than the previous line, up to and including the number entered by the user. On the next line write one fewer asterisk and continue by decreasing the number of asterisks by 1 for each successive lineuntil only one asterisk is displayed.For example, if the user enters the number 3, the output should be*********1.1 HintUse nested for loops; the outside loop controls the number of lines to write and the inside loop controls the number of asterisks to display on a line.The method System.out.print() will print a string without putting a new line after it.
Assignment 2Write a program that stimulates a bouncing ball by computing its height in feet at each second as time passes on a simulated clock. At time zero, the ball begins at height zero and has an initial velocity supplied by the user.(An initial velocity of at least 100 feet per second is a good choice.) After each second, change the height by adding the current velocity; then subtract 32 from the velocity. If the new height is less than zero, multiply both theheight and the velocity by -0.5 to simulate the bounce. Stop at the fifth bounce. The output from your program should have the following form:Enter the initial velocity of the ball: 100Time: 0 Height: 0.0Time: 1 Height 100.0Time: 2 Height 168.0Time: 3 Height 204.0Time: 4 Height 208.0Time: 5 Height 180.0Time: 6 Height 120.0Time: 7 Height 28.0Bounce !Time: 8 Height 48.023 Assignment 3Holy digits Batman! The Riddler is planning his next caper somewhere on Pennsylvania Avenue. In his usual sporting fashion, he has left the address in the form of a puzzle. The address on Pennsylvania is a four-digit numberwith the following properties:All four digits are dierentThe digit in the thousands place is three times the digit in the tensplaceThe number is oddThe sum of the digits is 27.Write a program that uses a loop or loops to nd the address where the Riddler plans to strike.3.1 HintFigure out how to get each of the ones, tens, hundreds, and thousands placerst. You will need to use division and the modulus operators.
Reviews
There are no reviews yet.