nmb++ is equal to nmb = nmb + 1. It only adds one till it’s 101, which is when it stops.
You should add a new variable, let’s call it total, and sum nmb to it every iteration.
public class T35{
public static void main(String[] args) {
int nmb;
int total = 0;
for(nmb= 1; nmb<= 100; nmb++){
total = total + nmb;
}
System.out.println(total);
}
}
This will do what you want.
2
solved Java program which sums numbers from 1 to 100