- 1

How can I make loop that only prints even number ?

14th Dec 2021, 7:44 AM
Jaspreet Singh
Jaspreet Singh - avatar
3 Respostas
+ 1
An even number is a number thay doesn’t leave any remainder after dividing by 2. An operator that gives you a remainder from division is modulo operator ‚%’ Example: 4%2 will equal zero, because 4 is divisible by 2 without any remainder. 5%2 equals 1, because you can put two ‚2’ inside the ‚5’, but there is still a ‚1’ left ( 2+2+1 ) Use it as an if statement inside a loop and you’re good to go ( run the Java course if you haven’t already ) Best of luck
14th Dec 2021, 8:24 AM
Nick
+ 1
Martin Taylor You’re right, thanks
14th Dec 2021, 10:13 AM
Nick