3 回答
TA贡献3条经验 获得超5个赞
public static void main(String[] args) {
int num = 1;
int i = 0;
while (num <= 1500) {
num += 2;
i++;
}
int count = 0;
for (int j = 0; j <= i; j=j+5) {
count++;
if (j % 5 == 0) {
if (count % 10 == 0) {
System.out.println(j + " ");
} else {
System.out.print(j + " ");
}
}
}
System.out.println("需要偶数" + i + "个");
}
TA贡献42条经验 获得超23个赞
public class ImoocTest {
public static void main(String[] args) {
int sum=0; //用来装加起来的数字
int num=1; //从1开始
int count1=0; //计算多少个偶数
int count2=0; //计算一行的数字
while(sum<1500){
if(num%2==0){
sum+=num;
count1++;
if(num%5==0&&sum<1500){
if(count2>9){
System.out.printf("\n");
count2=0;
}
System.out.print(num+" ");
count2++;
}
}
num++;
}
System.out.println("\n");
System.out.println("一共需要"+count1+"个偶数相加");
}
}
添加回答
举报