ÉèΪÊ×Ò³ ¼ÓÈëÊÕ²Ø

TOP

NSNumber(·â×°»ù±¾Êý¾ÝÀàÐÍ)
2015-07-20 17:23:16 À´Ô´: ×÷Õß: ¡¾´ó ÖРС¡¿ ä¯ÀÀ:1´Î
Tags£ºNSNumber ·â×° »ù±¾ Êý¾Ý ÀàÐÍ
//
//  main.m
//  OC05-task-04
//
//  Created by Xin the Great on 15-1-26.
//  Copyright (c) 2015Äê Xin the Great . All rights reserved.
//

#import 
  
   

int main(int argc, const char * argv[]) {
    @autoreleasepool {
        // insert code here...
        
        //////////////////////NSNumber//////////////////////
        //·â×°»ù±¾Êý¾ÝÀàÐÍ
        
        int intValue = 100;
        float floatValue = 3.14;
        BOOL boolValue = YES;
        
        NSNumber *intNumber = [[NSNumber alloc] initWithInt:intValue];
        NSLog(@"intNumber is %@", intNumber);
        NSNumber *floatNumber = [NSNumber numberWithFloat:floatValue];
        NSLog(@"floatNumber is %@", floatNumber);
        NSNumber *boolNumber = [NSNumber numberWithBool:boolValue];
        NSLog(@"boolNumber is %@", boolNumber);

        //°ü×°Ö®ºó¾Í¿ÉÒԷŵ½ÈÝÆ÷ÖÐ
        NSArray *arr = @[intNumber, floatNumber, boolNumber];
        NSLog(@"arr is %@", arr);
        
        
        //»¹Ô­³É»ù±¾Êý¾ÝÀàÐÍ
        float value = [floatNumber floatValue];
        int value2 = [intNumber intValue];
        NSLog(@"value is %.2f",value);
        NSLog(@"value2 is %d",value2);
        
        
        //¿ìËÙ´´½¨µÄ·½·¨
        NSNumber *intNum = @80;//---->  NSNumber *intNumber = [[NSNumber alloc] initWithInt:80];
        
        NSNumber *floatNum = @3.14;// ---->[NSNumber numberWithFloat:3.14];

        NSNumber *boolNum = @YES;// ---> [NSNumber numberWithBool:YES];
        
        NSNumber *charNum = @'a'; // ---> [NSNumber numberWithChar:'a'];
        
        
        //ÔËËã
        NSNumber *number = @(1 + 2);
        
        //Ö±½ÓÔÚÊý×éÖÐд
        NSArray *arr1 = @[@"string", @12, intNum, floatNum, boolNum, charNum, number];
        NSLog(@"arr1 is %@", arr1);
        
    }
    return 0;
}

  

¡¾´ó ÖРС¡¿¡¾´òÓ¡¡¿ ¡¾·±Ìå¡¿¡¾Í¶¸å¡¿¡¾Êղء¿ ¡¾ÍƼö¡¿¡¾¾Ù±¨¡¿¡¾ÆÀÂÛ¡¿ ¡¾¹Ø±Õ¡¿ ¡¾·µ»Ø¶¥²¿¡¿
·ÖÏíµ½: 
ÉÏһƪ£ºUVA 825 --Walking on the Safe S.. ÏÂһƪ£ºpoj1584--A Round Peg in a Groun..

ÆÀÂÛ

ÕÊ¡¡¡¡ºÅ: ÃÜÂë: (ÐÂÓû§×¢²á)
Ñé Ö¤ Âë:
±í¡¡¡¡Çé:
ÄÚ¡¡¡¡ÈÝ:

¡¤Spring Boot Java£º (2025-12-26 16:20:19)
¡¤Spring Boot¤ÇHello (2025-12-26 16:20:15)
¡¤Spring ¤Î»ù±¾¤«¤éŒ (2025-12-26 16:20:12)
¡¤C++Ä£°å (template) (2025-12-26 15:49:49)
¡¤C ÓïÑÔÖÐÄ£°åµÄ¼¸ÖÖ (2025-12-26 15:49:47)