Computer Science, asked by anmolpreet6712, 4 days ago

write a program to calculate the sum of odd numbers from 120 to 130

Answers

Answered by krishjaiswal1701
0

Answer:

class odd

{

public static void main()

{

for(int i=120;i<=130;i++)

{

if(i%2!=0)

System.out.println(i);

}

}

}

Explanation:

We have initialized value of variable "i" to 120 and then we are running a for loop till i is 130.

We check the condition each time whether "i" ehen divided from 2 is zero or not.

If it leaves a remainder after division with 2, Ithen it is an odd number and it prints that number.

Output:

121

123

125

127

129

Similar questions