Login using Social Account
     Continue with GoogleLogin using your credentials
To check if a particular line in a file starts with a set of strings we use the startsWith function in Scala.
The below code prints the lines starting with From:
import scala.io.Source
def count_from_lines() : Int = {
var countLines = 0
val filename = "/cxldata/datasets/project/mbox-short.txt"
for (line <- Source.fromFile(filename).getLines) {
if (line.startsWith("From:")) {
countLines = countLines + 1
}
}
return(countLines)
}
count_subject_linesmbox-short.txt which is located at /cxldata/datasets/project/mbox-short.txt and read it to get each line using getLines functionSubject:Note: If your logic is correct then your function should return 27.
Taking you to the next exercise in seconds...
No hints are availble for this assesment
Note - Having trouble with the assessment engine? Follow the steps listed here
Loading comments...