Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
当我按下按钮时,我试图只打印可被 10 整除的数字,请问有什么建议吗?而且我可以更改 for 循环,所以不要问这个问题。
-(IBAction)begin:(id)sender{ for (int k=0;k<=20;k++){ NSLog( @"%d",k); } }
if(k % 10 == 0) { NSLog( @"%d", k); }
那是模运算符。您本质上是在问“如果 k 除以 10 余数为零,则打印它”... :)
-(IBAction)begin:(id)sender{ for (int k=0;k<=20;k++){ if(k %10 == 0){ NSLog( @"%d",k); } }