FOR语句:
- public static void main(String[] args) {
- int count=0;
- for(int i=1;i<=100;i++)
- count+=i;
- System.out.println(count);
- }
WHILE循环:
- public static void main(String[] args) {
- int count=0,i=0;
- while((++i)<=100)
- count+=i;
- System.out.println(count);
- }
DO-WHILE循环
- public static void main(String[] args) {
- int count=0,i=0;
- do{
- count+=i;
- }while((++i)<=100);
- System.out.println(count);
- }