码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2019-06-18 17:14:57      阅读:172      评论:0      收藏:0      [点我收藏+]

标签:class   int   image   imp   public   str   code   string   print   

技术图片

 

代码:

 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 }

 

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

标签:class   int   image   imp   public   str   code   string   print   

原文地址:https://www.cnblogs.com/fandehui/p/11046164.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!