There is a more recent offering of this course. This is an archive of the
course which was offered in Fall 2018.
CS1011
Class Exercises
Week 5 Lecture 1 Class Exercises
## Exercise 1: Math
Using documentation for the [java.lang.Math](http://docs.oracle.com/javase/10/docs/api/java/lang/Math.html) class:
1. determine how to obtain the larger of two numbers, `a` and `b`.
2. write the code for when the numbers are `double`s
3. write the code for when the numbers are `long`s
4. what will be returned if `a` is a `long` and `b` is an `int`?
5. what will be returned if `a` is a `double` and `b` is an `int`?
## Exercise 2: Primitive to String Conversion
Using documentation for the [java.lang.Double](http://docs.oracle.com/javase/10/docs/api/java/lang/Double.html) class:
1. Explain why the class is referred to as a **wrapper** class
2. Determine which of the following is the correct way to convert a `double` to a `String` and explain why
```
double pi = Math.PI;
String number = Double.toString(pi);
```
or
```
Double pi = new Double(Math.PI);
String number = pi.toString();
```
3. Determine any differences required for converting an `int` to a `String`
## Exercise 3: Characters
Using documentation for the [java.lang.Character](http://docs.oracle.com/javase/10/docs/api/java/lang/Character.html) class:
1. Identify methods that would be useful for:
* Determining if a character is a digit
* Determining if a character is a letter
* Determining if a character is a vowel
* Determining if a character is capitalized
2. What characters are considered whitespace?
## Exercise 4: Strings
Using documentation for the [java.lang.String](http://docs.oracle.com/javase/10/docs/api/java/lang/String.html) class:
1. Write a program that asks the user to enter a phrase and then displays:
* The number of whitespace characters
* The number of letters
* If any digits were present
2. Write a program that asks the user to enter a phrase and then prints the phrase with each word displayed on a separate line.
3. Write code that takes a string, `phrase`, and ensures that there are no capital letters in it (if there are, they should be converted to lowercase characters).
4. Write code that will determine if a string, `phrase`, contains "**sap**" in it.