Object-C 练习

//
//  main.m
//  chapter8
//
//  Created by jimzhai on 13-1-28.
//  Copyright (c) 2013年 jimzhai. All rights reserved.
//

#import <Foundation/Foundation.h>
@interface Car : NSObject
{
    int V;
    int speed;
}
+(void)brakeDown;
-(int)getV;
-(void)setV:(int)V;
-(int)getSpeed;
-(void)setSpeed:(int)speed;
@end
@implementation Car

- (id)init
{
    self = [super init];
    if (self) {
        V=0;
        speed=0;
    }
    return self;
}//init
+ (void)brakeDown
{
    NSLog(@"car is broken!");
}//brakeDown
- (int)getV
{
    return V;
}//getV
-(void)setV:(int)_V
{
    V=_V;
}
-(void)setSpeed:(int)_speed
{speed=_speed;}
-(int)getSpeed
{
    return speed;
}
@end
int main(int argc, const char * argv[])
{
    id car = [Car new];
    NSLog(@"car V: %d     car speed: %d",[car getV],[car getSpeed]);
    [Car brakeDown];
    
    NSString *str1 = @"abcdefg";
    NSString *str2 = @"abcdefh";
    NSString *str3 = @"abcdefg";
    
    if([str1 isEqualToString:str2])
        NSLog(@"str1 is equal str2");
    if([str1 isEqualToString:str3])
        NSLog(@"str1 is equal str3");
    NSRange rang;
    rang = [str1 rangeOfString:@"cde"];
    NSString *str4 = [str1 stringByReplacingOccurrencesOfString:@"cde" withString:@"iii"];
    NSLog(@"%@",str4);
    
    NSArray *str = [NSArray arrayWithObjects:@"a",@"b",@"c",@"d",@"e",@"f",@"g",@"h",@"i",@"j",nil ];
    NSArray *array = [NSArray arrayWithArray:str];
    [str objectAtIndex:5];
    for(int i = 0 ; i < [array count]; i++)
        NSLog(@"%@",[array objectAtIndex:i]);
    
    
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值