Glame

第五次JAVA作业

package Home;

public class Home {

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        int a = 0, b = 0;
        do {
            if (a % 3 == 0) {
                b = b + a;
            }
            a++;
        } while (a <= 100);

        System.out.println("能被三整除的和为"+b);

    }

}

package Home;

public class Home {

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        int b = 0;
        for (int i = 0; i < 101; i++) {
            if (i % 3 == 0) {
                b = b + i;
            }
        }

        System.out.println("能被三整除的和为" + b);

    }

}

package Home;

public class Home {

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        int a = 0, b = 0;
        while (a <= 100) {
            if (a % 3 == 0) {
                b = b + a;
            }
            a++;
        }

        System.out.println("能被三整除的和" + b);

    }

}

package Home;

public class Home {

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        for (int i = 0; i < 10; i++) {
            if (i != 5) {
                System.out.println(i);
            }
        }

    }

}

package Home;

import java.util.Scanner;

public class Home {

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner input=new Scanner(System.in);
        System.out.println("请输入一个数字");
        int n=input.nextInt();
        int sum=1;
        for (; n>0; n--) {
            sum=sum*n;
        }
        System.out.println("该数的阶乘为"+sum);
    }

}

package Home;

import java.util.Scanner;

public class Home {

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner input = new Scanner(System.in);
        for (;;) {
            System.out.println("请输入学生成绩");
            int i = input.nextInt();
            if (i < 0 || i > 100) {
                System.out.println("输入错误");
            } else {
                System.out.println("输入成功");break;
            }
        }

    }

}

package Home;

public class Home {

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        double sum = 0;
        double money = 30000;
        for (int i = 0; i < 10; i++) {
            money = money * 1.06;
            sum = sum + money;
        }
        System.out.println("该员工十年后的年薪为" + (int) money + "总收入为" + (int) sum);
    }

}

package Home;

public class Home {

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        int a,b,c;
        for (int d=100;d<1000;d++) {
            a=d/100;
            b=d/10%10;
            c=d%10;
            if (a*a*a+b*b*b+c*c*c==d) {
                System.out.println("所有的水仙数为"+d);
            }
        }
    }

}

package Home;

import java.util.Scanner;

public class Home {

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner input=new Scanner(System.in);
        System.out.println("请输入年份");
        int year=input.nextInt();
        System.out.println("请输入月份");
        int month=input.nextInt();
        System.out.println("请输入天数");
        int day=input.nextInt();
        int sum=0;
        int days;
        for (; month-1 >0 ; month--) {
            if(month-1==1||month-1==3||month-1==5||month-1==7||month-1==8||month-1==10){
                days=31;
            }else if(month-1==4||month-1==6|month-1==9||month-1==11){
                days=30;
            }else if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0
                    && month-1 == 2) {
                System.out.println("该年为闰年");
                days = 29;
            } else {
                days = 28;
            }
            sum=sum+days;
        }
        sum=sum+day;
        System.out.println("今天是"+year+"年的第"+sum+"天");
    }

}

package Home;

import java.util.Scanner;

public class Home {

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner input=new Scanner(System.in);
        System.out.println("请输入一个四位整数");
        int num=input.nextInt();
        int[ ] a=new int[4];
        for (int i = 0; i < 4; i++) {
            a[i]=num%10;
            num=num/10;
        }
        System.out.println(a[0]*1000+a[1]*100+a[2]*10+a[3]);
    }

}

posted on 2021-04-02 18:27  Glame  阅读(52)  评论(0编辑  收藏  举报

导航