Home > Back-end >  Java solution
Java solution

Time:12-18

Write a complete Java program calculation, 1000 less than the sum of positive integers is a multiple of 3 and output result

CodePudding user response:

 
Public static void main (String [] args) {
int sum=0;
for (int i=1; i <=1000; I++) {
If (I % 3==0)
The sum +=I;
}
System. The out. Println (sum);
}

CodePudding user response:

int sum=0;
for(i=0; i<=1000; I++) {
If (I % 3==0) {sum +=I; }
}
System. The out. Println (sum);

CodePudding user response:

3 increasing multiple of 3, without doing modulus operation
int sum=0;
For (int I=3; i<=1000; I +=3) {
The sum +=I;
}
System. The out. Println (sum);
  • Related