package java_two;
import java.util.Scanner;
public class Classfour {
public static void main(String[] args) {
System.out.println("请输入一个数n=");
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int s = 0;
int i;
System.out.println(n);
for(i = 1; i <= n; i ++)
if(i%3==0 || i % 5 == 0)
s+=i;
System.out.println(s);
}
}
输入一个数n,打印出从1到n之间只包含3或5的倍数和,例如n=17,则求和的数为:3,5,6,9,10,12,15.
最新推荐文章于 2023-02-01 22:43:27 发布