#Methods
###Resources
###Key Words
Make sure you understand these before starting the exercises:
- Method signature
- Parameter
- Return type
- Return value
###Exercises
Complete these exercises in Methods.java
####1. Calculate Square
Write a method called calculateSquare
that takes an int as a parameter and returns the square of that integer.
ex: calculateSquare(2) returns 4
calculateSquare(3) returns 9
calculateSquare(4) returns 16
####2. Calculate Square Root
Write a method called calculateSquareRoot
that takes an int as a parameter and returns the square root of that integer.
ex: calculateSquareRoot(4) returns 2
calculateSquareRoot(9) returns 3
calculateSquareRoot(16) returns 4
How to calculate a square root
####3. toLowerCase
Write a method called toLowerCase
that takes a String as a parameter and returns the String in lower case.
ex: toLowerCase("Hello, World!") returns "hello, world!"
####4. isMultiple
Write a method called isMultiple
that takes 2 int parameters and determines if the second is a multiple of the first.
ex: isMultiple(2, 3) returns false
isMultiple(2, 4) returns true
isMultiple(5, 100) returns true
isMultiple(5, 101) returns false
How to determine if a number is a multiple of another number
####5. Pretty Integer
Write a method called prettyInteger
that takes an int as a parameter and prints the integer surrounded by asterisks with the length of each side equal to the given integer.
ex: prettyInteger(4) prints "**** 4 ****"
prettyInteger(10) prints "********** 10 **********"
Hint: this method does not return anything!
####6. Random
Write a method called random
that takes 2 ints as parameters and returns a random int within that range.
ex: random(1, 100) returns a random int between 1 and 100