I'm new in Java, it's my first attempt to write a program:
I need to write a program that prints the sum of all positive integers smaller
than 1000, that are divided by either 3 or 5.
Here is my (poorly) attempt. after compiling it is just receiving numbers and showing them :
import java.util.Scanner;
public class ex1 {
public static void main(String[] args) {
int num=1;
int count = 1;
while (count <=1000) {
if (count%3==0|count%5==0){
count = count+num;
count++;
}
}
System.out.println(count);
}
}
count = count+num;kind of seems wrong for whatcount"seems" to be used forcountfor two purposes - this won't work. You first line should benum += count.