NSArray作业1:放四个十进制三位数到一个数组中,然后按从小到大排序后组成一个新的数组
代码:(涉及到一部分NSArray的知识)
1 #import <Foundation/Foundation.h> 2 3 int main(int argc, const char * argv[]) { 4 @autoreleasepool { 5 int a=345,b=789,c=123,d=567; 6 NSLog(@"a=%d,b=%d,c=%d,d=%d",a,b,c,d); 7 NSNumber *numA=[[NSNumber alloc]initWithInt:a]; 8 NSNumber *numB=[[NSNumber alloc]initWithInt:b]; 9 NSNumber *numC=[[NSNumber alloc]initWithInt:c]; 10 NSNumber *numD=[[NSNumber alloc]initWithInt:d]; 11 NSArray *array1=[NSArray arrayWithObjects:numA,numB,numC,numD,nil]; 12 NSArray *array2=[array1 sortedArrayUsingSelector:@selector(compare:)]; 13 for(NSArray *array3 in array2){ 14 NSLog(@"%@",array3); 15 } 16 } 17 return 0; 18 }