Computer Science, asked by NidhaNeenu9966, 1 year ago

Write a program in java to calculate the sum of even and odd number in the range of 1 to 20

Answers

Answered by Rovinkavirsinghrana
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