zoukankan      html  css  js  c++  java
  • 练习题1

    //
    //  1.整数123456789,如何将这个整数的每一位数,从末位开始依次放入一个数组中,并将他们遍历出来
    //  2.如何将字符串@“abc123.xyz789”倒置
    //  3.将2013年05月05日转换成2013-05-05
    
    #import <Foundation/Foundation.h>
    
    int main(int argc, const char * argv[]) {
        @autoreleasepool {
            NSLog(@"第一题");
            NSInteger num=123456789;
            //NSNumber *newnum=@(num);
            NSString *strnum=[[NSString alloc]initWithFormat:@"%ld",num];
            NSMutableArray *arr=[NSMutableArray array];
            for (int i=8; i>=0; i--) {
                NSRange range;
                range.length=1;
                range.location=i;
                NSString *str=[NSString alloc];
                str=[strnum substringWithRange:range];
                [arr addObject:str];
            }
            for (id str1 in arr) {
                NSLog(@"%@",str1);
            }
            NSLog(@"第二题");
            NSString *string=@"abc123.xyz789";
            NSMutableString *newString=[[NSMutableString alloc]initWithCapacity:string.length];
            for (long i=string.length-1; i>=0; i--) {
                [newString appendFormat:@"%c",[string characterAtIndex:i]];
            }
            NSLog(@"%@",newString);
            NSLog(@"第三题");
            NSString *date=@"2013年05月05日";
            NSMutableString *Date=[NSMutableString stringWithString:date];
            NSRange rangeDate;
            int i=4;
            while (i<9) {
                rangeDate.length=1;
                rangeDate.location=i;
                [Date replaceCharactersInRange:rangeDate withString:@"-"];
                i+=3;
            }
            NSString *newdate=[Date substringToIndex:i];
            NSLog(@"%@",newdate);
        }
        return 0;
    }
  • 相关阅读:
    firefox上网问题解决
    ubuntu内核的编译安装
    ubuntu常用命令
    source insight 添加文件类型
    ubuntu版本查看命令
    百年孤独与拉丁美洲历史--转载
    Guess Number Higher or Lower II--困惑
    Symmetric Tree
    一棵开花的树
    yii2 mysql数据库读写分离配置
  • 原文地址:https://www.cnblogs.com/haitong-0311/p/5120864.html
Copyright © 2011-2022 走看看