+ 3
How can an array be used to add all odd numbers in a certain range of numbers eg from 1-100
2 Respuestas
+ 1
use a for loop from 1 to 100 and an If condition: if(variable%2!=0) sum+=variable.
+ 1
int sum=0;
for(int i=1; i<=100; i+=2){
sum+=i;
}
System.out.print(sum);