In this program, You will learn how to find the sum of the first 10 natural numbers using class in java.
Some natural numbers is: 1 2 3 4 5 6 7 8 9 10
class Main {
int i, s = 0;
void print() {
for (i = 1; i <= 10; i++) {
s = s + i;
}
System.out.println("Sum of 10 natural numbers:" + s);
}
public static void main(String args[]) {
Main obj = new Main();
obj.print();
}
}
Sum of 10 natural numbers:55