CodePudding user response:
The problem is the simplest one by one try, qualified, put together, but I feel more simple way,CodePudding user response:
Simple method is 3 and 7 is the least common multiple of 21, so start from 21st to 21 increases, the number of 100 conforms to this condition within canint sum=0;
For (int I=21; i<101; I +=21)
The sum +=I;
System.out.println(sum);
CodePudding user response:
System. Out.println (IntStream rangeClosed (1, 100). The filter (value - & gt; The value % 3==0 | | value % 3==0). The sum ());CodePudding user response:
One line of code,,,,CodePudding user response:
One of the 3 to 7CodePudding user response:
java8 flow in the form ofPublic class Test {
Public static void main (String [] args) {
Int sum=IntStream. RangeClosed (1, 100). The filter (value - & gt; The value % 3==0 | | value % 7==0). The sum ();
System. The out. Println (" sum="+ sum);//output and
Int [] ints.=IntStream rangeClosed (1, 100). The filter (value - & gt; The value % 3==0 | | value % 7==0). The toArray ();
System. The out. Println (Arrays. ToString (ints));//output all conform to the values
}
}