第六周作业

import java.util.Scanner;

public class Welcome{

public static void main(String[] args) {
cycle(); //三种循环
outPut(); //输出0-9,除了5
System.out.println(js(5));//求整数5的阶乘
student(); //学生成绩是否合法
System.out.println(getSalary(30000,10)); //工资为3w,10年后的薪水
}

static void cycle() {
int sum = 0;

//for循环
for(int i=0;i<100;i++) {

if(i%3==0) {
sum+=i;
}
}
System.out.println(+sum);
//while循环
int i = 0;
while(i>100) {

if(i%3==0) {
sum+=i;
}
i++;
}
System.out.println(sum);
//do...while循环
do {
if(i%3==0) {
sum+=i;
}
i++;
}while(i>100);
System.out.println(sum);
}
static void outPut() {

StringBuilder b = new StringBuilder("[");
for(int i=0;i<10;i++) {
if(i==5) {
}
else {
b.append(i+",");
}
}
b.setCharAt(b.length()-1, ']');
System.out.println(b);
}
static long js(int i) {
if(i==1) {
return 1;
}else {
return i*js(i-1);
}
}
static void student() {
Scanner scanner = new Scanner(System.in);
for(;;) {
int a = scanner.nextInt();
if(a<0||a>100) {
System.out.println("输入错误,从新输入");
}else{
System.out.println("输入合法");
break;
}
}
}
static long getSalary(int salary,int age) {
for(int i=0;i<age;i++) {
salary+=salary*6/100;
}
return salary;

   }
}

 

posted @ 2020-03-31 15:40  ㅤㅤㅤㅤㅤㅤㅤㅤㅤ  阅读(64)  评论(0编辑  收藏  举报