Logic & Coding Quarter 2 Intro Lab

Welcome back! Here is an introductory lab for Quarter 2 to get you back to into the groove of coding. Write a program to print the following: 1. Asterisk Triangle Write a program that creates a triangle pattern using asterisks. The triangle should have 5 rows, with each row containing an odd number of asterisks (1, 3, 5, 7, 9) centered with spaces. The first row should have 4 leading spaces, the second row 3 leading spaces, and so on. Output: * *** ***** ******* ********* 2. Number Pyramid Write a program that creates a pyramid pattern using numbers. Each row should display numbers that count down from the row number to 1, then back up to the row number. The pattern should have 5 rows total, with appropriate spacing to center each row. For example: Row 1: just "1" Row 2: "2" down to "1" and back to "2" (212) Row 3: "3" down to "1" and back to "3" (32123) And so on... Output: 1 212 32123 4321234 543212345 3. Write a program that generates a random number and asks the user to guess what the number is. If the user's guess is higher than the random number, the program should display "Too high, try again." If the user's guess is lower than the random number, the program should display "Too low, try again." The program should use a loop that repeats until the user correctly guesses the random number. Hint: Google the random function in java. 4. Write a program that when given a whole number, it creates a multiplication table of all whole numbers that come before the given number, and uses the number itself as well. It's ok if the table curves. For example: Please input a number 5 1 x 1 = 1 1 x 2 = 2 1 x 3 = 3 1 x 4 = 4 1 x 5 = 5 2 x 1 = 2 2 x 2 = 4 2 x 3 = 6 2 x 4 = 8 2 x 5 = 10 3 x 1 = 3 3 x 2 = 6 3 x 3 = 9 3 x 4 = 12 3 x 5 = 15 4 x 1 = 4 4 x 2 = 8 4 x 3 = 12 4 x 4 = 16 4 x 5 = 20 5 x 1 = 5 5 x 2 = 10 5 x 3 = 15 5 x 4 = 20 5 x 5 = 25 5. Write a program that takes in two numbers for input, and returns the value of the first number raised to the power of the 2nd number. For example: Input: 2 3 Output: 8 Advanced ASCII Art Loop Problems 6. Diamond with Border Write a program that creates a diamond shape with asterisks and a border of plus signs: + +*+ +***+ +*****+ +*******+ +*****+ +***+ +*+ + 7. Alternating Triangle Write a program that creates a triangle where each row alternates between two characters. The user should input the height and the two characters to use: Input: 7 # @ Output: # @@@ ##### @@@@@@@ ######### @@@@@@@@@@@ ############# 8. Hollow Hourglass Write a program that creates a hollow hourglass pattern with asterisks. The user inputs the height (must be odd): Input: 9 Output: ********* * * * * * * * * * * * * * ********* 9. Number Spiral Write a program that creates a square spiral of numbers. The user inputs the size (must be odd): Input: 5 Output: 1 2 3 4 5 16 17 18 19 6 15 24 25 20 7 14 23 22 21 8 13 12 11 10 9 10. ASCII Wave Write a program that creates a wave pattern using characters. The user inputs the amplitude (height), wavelength, and number of waves: Input: 3 8 2 (amplitude=3, wavelength=8, waves=2) Output: * * * * * * * * * * * * * * * * import java.util.Scanner; public class Main { public static void main(String args[]) { // Out of bounds!!! Scanner myScanner = new Scanner(System.in); //Your scanner initialized, use as you see fit. //Out of bounds!!! } }