NSArray *arr = @[@"5",@"1",@"4",@"3",@"4",@"10",@"6",@"14",@"16",@"30",@"20",@"18"];
int sum = [[arr valueForKeyPath:@"@sum.intValue"] intValue];//求和
float avg = [[arr valueForKeyPath:@"@avg.floatValue"] floatValue];//求平均值
int max = [[arr valueForKeyPath:@"@max.intValue"] intValue];//求最大值
int min = [[arr valueForKeyPath:@"@min.intValue"] intValue];//求最小值
NSLog(@"和:%d \n 平均值:%f \n 最大值:%d \n 最小值:%d",sum,avg,max,min);
网友评论