TQC+ JAVA 309 迴圈倍數判斷
import java.io.*;
class JPA03 {
public static void main(String argv[]) throws IOException {
int sum=0;
BufferedReader buff=new BufferedReader(new InputStreamReader(System.in));
int a=Integer.parseInt(buff.readLine());
for(int i=0;i<=a;i++){
if(i%7==0){
continue;
}
if(i%3==0||i%5==0){
sum+=i;
}
}
System.out.println("Answer: " + sum);
}
}
沒有留言:
張貼留言