Write a program in java to calculate the sum of even and odd number in the range of 1 to 20
Answers
Answered by
4
Answer:
sum of even number
Explanation:
public class Sum {
public static void main(String[] args){
int sum=0;
for(int i=2; i<=20; i=i+2){
sum = sum + i;
}
System.out.println(sum);
}
}
and the same process flow by odd number but only for loop is change. add the odd number in for loop
for(int i=1; i<=20; i=i+2)
Similar questions
English,
6 months ago
CBSE BOARD X,
1 year ago
English,
1 year ago
Math,
1 year ago
Math,
1 year ago