0

我有三个变量,一个叫做 A = 2012,第二个叫做 B = 2020,第三个是 C = B - A。C 是年份的差异。现在我想在屏幕上看到两个日期之间的年份:2012 2013 2014 2015 2016 2017 2018 2019 2020。我尝试了不同的解决方案,但我做不到,我认为正确的方法是循环。这样对吗?你能告诉我怎么做吗?谢谢你。

4

2 回答 2

1

我假设你的意思是循环循环?你可以试试这个:

int a = 2012;             // Holds the first year
int b = 2020;             // Holds the last year
int c = b - a;            // Holds the difference of the a and b
while(a<=b) {             // Execute this as long as a is equal or less then b
    NSLog("Year: %d", a); // Print the year to the console
    a++;                  // Increment the value of a with 1
}
于 2012-04-18T19:36:29.487 回答
-2
for(int i=0;i<=c;i++)
{
 NSLog(@"The Year is %i \n",a+i);
}
于 2012-04-18T19:22:27.590 回答