1.while语句:
示例代码:
package com.WhileDemo;
public class WhileDemo {
public static void main(String[] args)
{
int i=0;
while(i<=5) {
System.out.println(i);
i++;
}
}
}
2:do...while语句:
示例代码:
package com.DoWhileDemo;
public class DoWhileDemo {
public static void main(String[] args)
{
int i=0;
int sum=0;
do{
sum=sum+i;
i+=2;
}
while(i<=50);
System.out.println(sum);
}
}
3:for循环:
示例代码:
package com.ForDemo;
public class ForDemo {
public static void main(String[] args) {
int sum=0;
for(int i=0;i<=100;i++)
if(i%3!=0) {
sum=sum+i;
}
System.out.println(sum);
}
}
4: