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:
*
***
*****
*******
*********
2:
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. 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
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!!!
}
}