 • Print
This chapter is from the book

## Exercises

1. In the Scala REPL, type 3. followed by the Tab key. What methods can be applied?
2. In the Scala REPL, compute the square root of 3, and then square that value. By how much does the result differ from 3? (Hint: The res variables are your friend.)
3. Are the res variables val or var?
4. Scala lets you multiply a string with a number—try out "crazy" * 3 in the REPL. What does this operation do? Where can you find it in Scaladoc?
5. What does 10 max 2 mean? In which class is the max method defined?
6. Using BigInt, compute 21024.
7. What do you need to import so that you can get a random prime as probablePrime(100, Random), without any qualifiers before probablePrime and Random?
8. One way to create random file or directory names is to produce a random BigInt and convert it to base 36, yielding a string such as "qsnvbevtomcj38o06kul". Poke around Scaladoc to find a way of doing this in Scala.
9. How do you get the first character of a string in Scala? The last character?
10. What do the take, drop, takeRight, and dropRight string functions do? What advantage or disadvantage do they have over using substring?