< Back
Page 8 of 8
This chapter is from the book
Exercises
- In the Scala REPL, type 3. followed by the Tab key. What methods can be applied?
- 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.)
- Are the res variables val or var?
- 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?
- What does 10 max 2 mean? In which class is the max method defined?
- Using BigInt, compute 21024.
- 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?
- 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.
- How do you get the first character of a string in Scala? The last character?
- What do the take, drop, takeRight, and dropRight string functions do? What advantage or disadvantage do they have over using substring?
< Back
Page 8 of 8