求1001到n(n<10000)中所有奇数,所有各位数字之和是25的倍数的数,并将它们求和显示出来。

时间:2019-06-18 17:14:57   收藏:0   阅读:172

技术图片

 

代码:

 1 import java.util.*;
 2 public class Main {
 3     public static void main (String [] args) {
 4         int q,b,s,g,sum=0;
 5         Scanner scan=new Scanner(System.in);
 6         int n=scan.nextInt();
 7         for(int i=1001;i<n;i++) {
 8             int total=0;
 9             if(i%2==1) {
10                 g=i%10;
11                 s=i/10%10;
12                 b=i/100%10;
13                 q=i/1000;
14                 total=q+b+s+g;
15                 if(total%25==0) {
16                     sum+=i;
17                 }
18             }
19         }
20         System.out.println(sum);
21     }
22 }

 

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!