一组给定数组中的3的倍数 [英] multiple of 3 in a set of given array
本文介绍了一组给定数组中的3的倍数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
int [] a = {15,51,2,12,280,5,43,30,33};
你可以告诉我代码只有上面一组数字的3的倍数。
解决方案
public void GetMultipleOfNumber( int [] Array, int 数量)
{
// 代码
}
你可以自己做,不是吗?
很简单,方法头是给定的。
你只需要通过你的数组迭代(for-slope)。
然后做一个模数! (Array [i]%Number)。
如果模数返回0则很好(例如15%3 = 0)
那么你可以用你想要的结果做什么。
已完成。基本的东西。作业...
int[] a={ 15,51,2,12,280,5,43,30,33};
can u please tell me code to take only the numbers which is multiples of 3 from above set of numbers.
解决方案
public void GetMultipleOfNumber(int[] Array, int Number) { //Code }
You can do this on your own, can't you?
Its easy, the method head is given.
You just need to iterate (for-slope) through your array.
Then do a modulo on that! (Array[i]%Number).
If the modulo returns 0 it's good (E.g. 15%3 = 0)
Then you can do with the result what you want.
Finished. Basic stuff. Homework...
这篇关于一组给定数组中的3的倍数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文