public class Test { public static void main(String[] agrs) { int i,s = 0; int a[] = { 10,20,30,public class Test {public static void main(String[]agrs) {int i,s = 0;int a[] = { 10,20,30,40,50,60,70,80,90 };for (i = 0; i < a.length;i++){if (a[i] % 3 =

来源:学生作业帮助网 编辑:作业帮 时间:2024/11/17 21:41:57

public class Test { public static void main(String[] agrs) { int i,s = 0; int a[] = { 10,20,30,public class Test {public static void main(String[]agrs) {int i,s = 0;int a[] = { 10,20,30,40,50,60,70,80,90 };for (i = 0; i < a.length;i++){if (a[i] % 3 =
public class Test { public static void main(String[] agrs) { int i,s = 0; int a[] = { 10,20,30,
public class Test {
public static void main(String[]agrs) {
int i,s = 0;
int a[] = { 10,20,30,40,50,60,70,80,90 };
for (i = 0; i < a.length;i++){
if (a[i] % 3 == 0) {
s += a[i];
System.out.println("s="+ s);
}
}
}

程序的输出结果为:

public class Test { public static void main(String[] agrs) { int i,s = 0; int a[] = { 10,20,30,public class Test {public static void main(String[]agrs) {int i,s = 0;int a[] = { 10,20,30,40,50,60,70,80,90 };for (i = 0; i < a.length;i++){if (a[i] % 3 =
程序输出的结果是:
s=30
s=90
s=180
for 循环会将数组a的每一个元素遍历一遍.
当遇到一个能被三整除的元素时,叠加在变量s上,并输出s的值.
第一个能被3整除的是30,此时s = 0 + 30 =30
第二个能被3整除的是60,此时s = 30 + 60 = 90
第三个能被3整除的是90,此时s = 90 + 90 = 180