-->
当前位置:首页 > 题库 > 正文内容

程序填空题:the Bands

Luz4年前 (2021-05-10)题库638
The following program reads a lot of lines of names, each name represents an artist or a band.
The name of a band begins with "the", that is easy to be recognized.
The last word in that line is the nationality of the band or the artist.

Our job it to summarize all the nationalities of all the bands, then print them.
For example, for input:
```
Taylor Swift U.S.
the Beattles U.K.
the Dynasty Tang China
the May Flower China
```

The output should be:
```
China
U.K.
```

Now, fill in the blanks below:

```Java
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
ArrayList lst = new ArrayList();
while ( in.hasNextLine() ) {
String line = in.nextLine();
lst.add(line.split(" "));
}
Set ret = lst.stream()
.filter(@@[x->x[0].equals("the")](2))
.map(@@[x->x[x.length-1]](2))
.collect(Collectors.@@[toSet()](1));
ArrayList r = new ArrayList(ret);
Collections.sort(r);
for ( String s: r ) {
System.out.println(s);
}
in.close();
}
}
```






答案:
第1空:x->x[0].equals("the")

第2空:x->x[x.length-1]

第3空:toSet()

发表评论

访客

◎欢迎参与讨论,请在这里发表您的看法和观点。