- 1

How to add only even number from 1 to n?

Arrays

29th Aug 2016, 6:48 PM
Abhishek kumar
Abhishek kumar - avatar
2 Réponses
0
ArrayList<Integer> EvenNums = new ArrayList<Integer>(); int n = 20; for(int i = 1; i <=n; i++){ if(i % 2 == 0){ EvenNums.add(i); } } This is a basic example of how to do it, you can modify it to fit your needs.
29th Aug 2016, 10:58 PM
Ousmane Diaw
- 1
Lemme throw a question to you back. Is it to add (join) or add (arithmetical)?
30th Aug 2016, 1:42 AM
Ezekiel Oladejo
Ezekiel Oladejo - avatar