打印数组中可被 3 整除的数字数量
我是 Java 新手,正在开发一个基本程序,该程序查看数组并打印数组中可被 3 整除的数字数量。我在让它正常工作时遇到了一些麻烦。这是我到目前为止得到的代码。
package arraysearch;
public class Intsearch {
public static void main(String[] args) {
}
public static void multiple_3 (int[] a, int b) {
b=0;
}
{
int[] numarray ={3, 9, 45, 88, 23, 27, 68};
{
if (numarray % 3)==0;
b = b+1;
}
System.out.println("This is the amount of numbers divisible by 3:" +b)
}
}
I'm new to Java and working on a basic program that looks through an array and gives prints the amount of numbers in the array that are divisible by 3. I'm having some trouble getting it to work right. Here is the code that I've got so far.
package arraysearch;
public class Intsearch {
public static void main(String[] args) {
}
public static void multiple_3 (int[] a, int b) {
b=0;
}
{
int[] numarray ={3, 9, 45, 88, 23, 27, 68};
{
if (numarray % 3)==0;
b = b+1;
}
System.out.println("This is the amount of numbers divisible by 3:" +b)
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
试试这个(Java 7):
Java 8 更新:
Try this (Java 7):
Java 8 update:
您需要一个 for 循环来按顺序评估数组中的每个项目:
You'll need a for loop to evaluate each item in the array sequentially:
请尝试:
Please try :