- 1
How to add only even number from 1 to n?
Arrays
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.
- 1
Lemme throw a question to you back. Is it to add (join) or add (arithmetical)?