- 53
- 0
- 约3万字
- 约 29页
- 2021-10-27 发布于天津
- 举报
《 Java 语言程序设计(基础篇) 》 (第 10 版 梁勇 著)
第二十一章 练习题答案
21.1
import java.util.*;
public class Exercise21_01 {
public static void main(String[] args) {
LinkedHashSetString set1 = new LinkedHashSetString(Arrays.asList(
new String[]{ George , Jim , John , Blake , Kevin , Michael }));
LinkedHashSetString set1Clone1 = (LinkedHashSetString)set1.clone();
LinkedHashSetString set1Clone2 = (LinkedHashSetString)set1.clone();
LinkedHashSetString set2 =
LinkedHashSetString set2 =
Ryan }));new String[] { George , Katie , Kevin ,
Ryan }));
set1.addAll(set2);
set1Clone1.removeAll(set2);
set1Clone2.retainAll(set2);
The union of the two sets is The difference of the two sets is
The union of the two sets is
The difference of the two sets is
The intersection of the two sets is
+ set1);
+ set1Clone1);
+ set1Clone2);
System.out.println(
System.out.println(
}
}
21.1 附加
import java.util.*;
public class Exercise21_01Extra {
public static void main(String[] args) {
System.out.print( Enter a string: );
Scanner input = new Scanner(System.in);
String s = input.nextLine();
Character[] list1 = { A , E , I , O , U };
SetCharacter vowels = new HashSet(Arrays.asList(list1));
SetCharacter vowelsInString = new HashSet();
SetCharacter consonantsInString = new HashSet();
int numbeOfVowels = 0;
int numbeOfConsonants = 0;
for ( int i = 0; i s.length(); i++) {
char ch = Character.toUpperCase(s.charAt(i));
if (Character.isLetter(ch)) {
if (vowels.contains(ch)) {
if (!vowelsInString.contains(ch)) {
vowelsInString.add(ch);
numbeOfVowels++;
}
}
else if (!consonantsInString.contains(ch)) { consonantsInString.add(ch);
numbeOfConsonants++;
}
}
}
The number of vowels is The number of consonants is
The number of vowels is
The number of consonants is
+ numbeOfVowels);
+ numbeOfConsonants);
System.out.println(
}
}
21.2
import java.util.*;
import java.io.*;
public class Exercise21_02 {
public static void main(String[] args) {
if (args.length != 1) {
System.out.println(
Usage: java Exercise21_02 fullfilename );
System.e
您可能关注的文档
最近下载
- 数字图像处理图像编码.ppt VIP
- 湖北城市建设职业职业技术学院2025年高职单招考试城市燃气工程技术专业考试大纲.pdf VIP
- 长帝电烤箱TV42W使用说明书用户手册.pdf
- 气象学与气候学课件.pptx
- 电子科技大学《光电图像处理》 第六章 图像编码与压缩 ppt课件.pptx VIP
- 对外经济贸易大学2021-2022学年《Python程序设计》期末考试试卷(A卷)及标准答案.docx
- 高考数学极值点偏移练习题(含答案).docx VIP
- 化工过程安全管理导则-装置安全规划与设计课件.pptx VIP
- 五脏与情志 jt叔叔 JT叔叔伤寒杂病论慢慢教(.)五脏与情志.doc VIP
- 图像处理与分析图像的编码技术.ppt VIP
原创力文档

文档评论(0)