ВУЗ: Не указан
Категория: Не указан
Дисциплина: Не указана
Добавлен: 02.01.2026
Просмотров: 420
Скачиваний: 0
110Chapter 9 Files and Regular Expressions
4.Write a Scala program that reads a text file containing only floating-point numbers. Print the sum, average, maximum, and minimum of the numbers in the file.
5.Write a Scala program that writes the powers of 2 and their reciprocals to a file, with the exponent ranging from 0 to 20. Line up the columns:
11
20.5
4 0.25
... ...
6.Make a regular expression searching for quoted strings "like this, maybe with \" or \\" in a Java or C++ program. Write a Scala program that prints out all such strings in a source file.
7.Write a Scala program that reads a text file and prints all tokens in the file that are not floating-point numbers. Use a regular expression.
8.Write a Scala program that prints the src attributes of all img tags of a web page. Use regular expressions and groups.
9.Write a Scala program that counts how many files with .class extension are in a given directory and its subdirectories.
10.Expand the example with the serializable Person class that stores a collection of friends. Construct a few Person objects, make some of them friends of another, and then save an Array[Person] to a file. Read the array back in and verify that the friend relations are intact.