The first chapter of Scala exercises

Source: Internet
Author: User
Tags multiply strings square root

1. The Scala interpreter reads an expression, evaluates it, prints it out, and then continues reading the next expression. This process is called "read-evaluate-print-loop", or REPL.

Exercises

1. Type 3 in the Scala repl, and then press the TAB key. What are the methods that can be applied.

I was typing "3." Press the TAB key to have the following output

2. In Scala repl, calculate the square root of 3 and then square the value, now, how much difference does this result have with 3? (Hint: res variable is your friend)

Import Scala.math._ First (the underscore indicates a wildcard character)

3. The res variable is Val or var.

I think it's Val.

4. Scala allows you to use numbers to multiply strings----go to Repl to try "crazy", what this operation does. How to find this operation in Scaladoc

Repeat Crazy 3 times

Search for string directly in Scaladoc

What is the meaning of 5.10 Max 2. The Max method is defined in which class.

Richint Class (Why direct search Max not found, not good)

6. Use bigint to calculate 2 of the 1024-time Square

7. What you need to introduce in order to use any qualifiers before probableprime and Radom to get random primes using probableprime (random).

Import Scala.util._

Import Scala.math.bigint._

Online search for, do not know why ...

8. One way to create a random file is to generate a random bigint, then convert it to 36, output a string like "Qsnveffwfweq434ojjlk", consult the Scaladoc, and find a way to implement that logic in Scala.

9. How to get the first and trailing characters of a string in Scala.

Take, Drop, takeright, dropright What are these string functions for? Compared with substring, they have the advantages and disadvantages.

(1) in the Stringlike

Take:selects first n elements. (select n characters at the beginning)

Takeright:selects last n elements. (select n characters at the end)

(2) Stringops

Drop:selects all elements except first n ones. (select n characters except the beginning)

Dropright:selects all elements except last n ones. (Select n characters in addition to the end)

(3) StringBuilder


SUBSTRING: Select the substring, which is to construct a new string

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.