Try this ...
public class Solution {
public static void main(String[] args) {
long t = 1000;
long sum = 0;
for(int i = 1; i<t; i++){
if(i%3 == 0 || i%5 == 0){
sum = sum + i;
}
}
System.out.println(sum);
}
}