Vrite a program to find the sum of the 1st 10 odd natural numbers.
atrs7391:
Language
Answers
Answered by
0
Answer:
hsbdbcbfbsh KGB 4bdbrnsj ed jd djdn end hdhea
Answered by
0
Here is your answer:
package com.company;
public class Main {
public static void main(String[] args) {
int sum = 0;
for (int j = 0; j < 20; j++) {
if (j%2==1){
//System.out.println(j);
//You can add the above line if you want to display the odd numbers too.
int sum2 = j;
sum2 = sum2+j;
sum = sum2;
}
}
System.out.println("The sum of first 10 odd natural numbers are: "+sum);
}
}
Attachments:
Similar questions