It's a question for the moon

Asked 2 years ago, Updated 2 years ago, 26 views

        int total=0;
        for(int i=1; i<100; i++){
            total=total+i;

            System.out.println(total);
            }
        }

It's this chord. From what I've tried, 1 3 6 10 15 21 28 36 45 55 It stretches out like this It comes out up to 4950

But I don't know how it stretches like this

total:0 i:1 added value: 1
Total:1 i:2 added value:3
Total:2 i:3 added value:5

Doesn't it stretch like this? It's over five and six, but I don't understand!

java

2022-09-22 11:34

2 Answers

1
1+2 = 3
1+2+3 =6
1+2+3+4=10
1+2+3+4+5=15

This is what happens.


2022-09-22 11:34

I'll draw a table and explain it to you.

It goes like this. When total:1 and i:2 are added:3 goes into the total value, and the next total value is 3, not 2. It's three plus three, so it's six.


2022-09-22 11:34

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.