3.30号作业

public static void main(String[] args) {
        /*
         * 用for循环
         */
        
        int sum= 0;//定义变量计数器
        for (int i = 1; i < 100; i++) {
            if (i%3==0) {
                sum +=i;
            }
        }
        System.out.println(sum);
        /*
         * 用while循环
         */
            int sum1=0;
            int i=1;
            while(i<=100){
                if (i%3==0) {
                    sum1 +=i;
                }
                i++;
            }
            System.out.println(sum1);
            /*
             * 用do while循环
             */
            int j = 1;
            int sum2 = 0;
            do {
                if (j%3==0) {
                    sum2 +=j;
                }
                j++;
            } while (j<=100);
            System.out.println(sum2);
    }
public static void main(String[] args) {
        for (int i = 0; i < 10; i++) {
            if (i==5) {
                continue;
            }
            System.out.println(i);
        }
    }
public static void main(String[] args) {
        Scanner sca = new Scanner(System.in);
        System.out.println("输入一个数");
        int a = sca.nextInt();
        int i = 0;
        for (i = 0; i < a; i++) {
            System.out.print(i+"*");
        }
        System.out.println(i);
    }
public static void main(String[] args) {
    Scanner sca = new Scanner(System.in);
    System.out.println("输入成绩");
    int a = 0;
    a = sca.nextInt();
    while(true){
        if (a>0&&a<=100) {
            System.out.println("您输入对了");
            break;
        }else{
            System.out.println("您输入错了重新输入");
            a=sca.nextInt();
        }
        }
        
    }
public static void main(String[] args) {
        int salary = 30000;
        int sum = 0 ;
        for (int i = 0; i < 11; i++) {
            salary+=salary*0.06;
            sum+=salary;
        }
        System.out.println(salary);
        System.out.println(sum);
    }

 

你可能感兴趣的:(3.30号作业)