/*
1.已知某学校的教学课程内容安排如下:
Tom CoreJava
John Oracle
Susan Oracle
Jerry JDBC
Jim Unix
Kevin JSP
Lucy JSP
1)使用一个字典,以老师的名字作为键,老师教授的课程作为值,表示上述课程安排
2)增加了一位新老师Allen 教JDBC
3)Lucy 改为教 CoreJava
4)遍历字典,输出所有老师及老师教授的课程
5)利用字典,输出所有JSP的老师
*/
main.m
//1.
NSDictionary *teach = @{@"Tom":@"CoreJava",
@"John":@"Oracle",
@"Susan":@"Oracle",
@"Jerry":@"JDBC",
@"Jim":@"Unix",
@"Kevin":@"JSP",
@"Lucy":@"JSP"};
//2.
NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithDictionary:teach];
[dic setObject:@"JDBC" forKey:@"Allen"];
//3.
[dic setObject:@"CoreJava" forKey:@"Lucy"];
//4.
//获取所有的键
NSArray *allkeys = [dic allKeys];
//遍历 键 数组
for (NSString *key in allkeys)
{
NSLog(@"%@ - %@",key,[dic objectForKey:key]);
}
//5.
NSLog(@"教JSP的老师有:");
for (NSString *key in allkeys)
{
NSString *lesson = [dic objectForKey:key]
//判断两个字符串[内容]是否相等
if([lesson isEqualToString:@"JSP"])
{
NSLog(@"%@ - %@",key,[dic objectForKey:key]);
}
}
网友评论