Closed. This question needs debugging details。它当前不接受答案。
                            
                        
                    
                
            
                    
                
                        
                            
                        
                    
                        
                            想改善这个问题吗? Update the question,所以它是on-topic,用于堆栈溢出。
                        
                        5年前关闭。
                    
                
        

我的代码我不知道下一步该怎么做我完全是新手

        int number = lb;
        while(number <= ub){
            if (number % 7 == 0 && number % 15 == 0 && number % 17 == 0 && number % 30 != 0 ){
                sum+= number;

            }
            number++;
        }
        System.out.println("Answer: " + sum);
    }

}

最佳答案

使用最新版本的Java 8在一行中完成此操作:

package com.example;

import static java.util.stream.IntStream.rangeClosed;
import static java.lang.System.out;

public class Main {
    public static void main(String[] args) {
        out.println(rangeClosed(1, 1000)
                   .filter(n -> n % 13 == 0 || n % 15 == 0 || n % 17 == 0)
                   .filter(n -> n % 30 != 0)
                   .sum());
    }
}

09-15 18:16