Java Example – Summation (Sum of Numbers)
The following example demonstrates using a do...while loop to compute the sum of integers from 0 to 100:
Main.java File
public
class
Main
{
public
static
void
main
(
String
[
]
args
)
{
int
limit
=
100
;
int
sum
=
0
;
int
i
=
1
;
do
{
sum
=
sum
i
;
i
++;
}
while
(
i
<=
limit
)
;
System
.
out
.
println
(
"
sum=
"
sum
)
;
}
}
The output of the above code is:
sum=5050
Java Examples