1.
for循环:
package finish;
import java.util.*;
public class csy {
public static void main(String[] args) {
int sum=0;
for (int i = 1; i <=100 ; i++) {
if (i%3==0){
sum+=i;
}
}
System.out.println("1-100之间能被3整除的和是"+sum);
}
}
![](https://img2020.cnblogs.com/blog/1967842/202004/1967842-20200401115144785-1990013832.png)
while循环:
package finish;
import java.util.*;
public class csy {
public static void main(String[] args) {
int sum=0;
int i=0;
while(i<=100){
if(i%3==0){
sum+=i;
}
i++;
}
System.out.println("1-100之间能被3整除的和是"+sum);
}
}
![](https://img2020.cnblogs.com/blog/1967842/202004/1967842-20200401115222538-1516505534.png)
do while 循环:
package finish;
import java.util.*;
public class csy {
public static void main(String[] args) {
int sum=0;
int i=0;
do{
if(i%3==0){
sum+=i;
}
i++;
}while(i<=100);
System.out.println("1-100之间能被3整除的和是"+sum);
}
}
![](https://img2020.cnblogs.com/blog/1967842/202004/1967842-20200401115246068-1543606475.png)
2.package finish;
import java.util.*;
public class csy {
public static void main(String[] args) {
for(int i=0;i<=9;i++){
if(i==5){
continue;
}
System.out.print(i);
}
}
}
![](https://img2020.cnblogs.com/blog/1967842/202004/1967842-20200401115307372-948738526.png)
3.package finish;
import java.util.*;
public class csy {
public static void main(String[] args) {
Scanner csy=new Scanner(System.in);
System.out.println("请输入一个整数n:");
int n = csy.nextInt();
int x=1;
int y=n;
for(int i=0;i<n;i++){
y=n-i;
x=y*x;
}
System.out.println("n的阶乘为:"+x);
}
}
![](https://img2020.cnblogs.com/blog/1967842/202004/1967842-20200401115340361-476314382.png)
4.package finish;
import java.util.*;
public class csy {
public static void main(String[] args) {
Scanner csy=new Scanner(System.in);
for(int i=1;;i++){
System.out.println("请输入一位学生成绩");
int score=csy.nextInt();
if(score<0||score>100){
System.out.println("输入成绩有误,请重新输入:");
}else{
System.out.println("该学生成绩为:"+score);
break;
}
}
}
}
![](https://img2020.cnblogs.com/blog/1967842/202004/1967842-20200401115407964-590284169.png)
5.package finish;
import java.util.*;
public class csy {
public static void main(String[] args) {
double x=30000;
double sum=0;
for(int year=1;year<=10;year++){
x=x*1.06;
sum+=x;
}
System.out.println("员工10年后的年薪为:"+x);
System.out.println("员工未来10年总收入为:"+sum);
}
}
![](https://img2020.cnblogs.com/blog/1967842/202004/1967842-20200401115432288-1841182350.png)