标签:foundation框架 objective-c ios开发 string 打印图形
/* 5 根据输入的内容打印出菱形 */ +(void)print:(NSInteger)count blankString:(NSString*)blankString flagString:(NSString*)flagString /* { NSMutableString * ptr = [[NSMutableString alloc]init]; for (NSInteger i = 0; i < count; i++) { for (NSInteger j = 0; j < count; j++) { if (abs((int)(i-count/2))+abs((int)(j - count/2))==count/2) { [ptr appendString:flagString]; } else { [ptr appendString:blankString]; } } [ptr appendString:@"\n"]; } NSLog(@"\n%@",ptr); } */ { NSMutableString * ptr = [[NSMutableString alloc]init]; for (NSInteger i = 0; i < count; i++) { for (NSInteger j = 0; j < count; j++) { if (abs((int)(i - count/2))+abs((int)(j - count/2))==count/2) { [ptr appendString:flagString]; } else { [ptr appendString:blankString]; } } [ptr appendString:@"\n"]; } NSLog(@"\n%@",ptr); } //count 表示正方形边长 //flagString 组成菱形的边 //blankString 组成背景正方形 //比如 [class print:5 blankString:@“+”flagString:@“#”]; /* + + # + + + # + # + # + + + # + # + # + + + # + + */ /*
版权声明:本文为博主原创文章,未经博主允许不得转载。
标签:foundation框架 objective-c ios开发 string 打印图形
原文地址:http://blog.csdn.net/u012701023/article/details/47070559