魔幻的猫头鹰

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
package test;

public class test {
    public static void main(String args[]){
        //分别用for循环,while循环,do循环求1到100之间的所有被3整除的和
        int a = 1;
        int b = 100;
        while(a<=b){
            if(a%3==0){
                System.out.println(a+"能被三整除");
            }
            a++;
        }
        for(a=1;a<=b;a++){
            if(a%3==0){
                System.out.println(a+"能被三整除");
            }
        }
        do{
            if(a%3==0){
                System.out.println(a+"能被三整除");
            }
            a++;
        }while(a<=b);
    }
}

 

 

 

package test;

public class test1 {
    public static void main(String args[]){
        //输出0-9之间的数不包括5
        for(int a = 0;a<=9;a++){
            if(a!=5){
                System.out.println(a);
            }
        }
    }
}

 

 

 

package test;

import java.util.Scanner;

public class test2 {
    public static void main(String args[]){
        //编写一个程序,求n阶乘
        Scanner input = new Scanner(System.in);
        System.out.println("请输入一个数求阶乘");
        int n = input.nextInt();
        int sum = 1;
        for(int a =1;a<=n;a++){
            sum*=a;
        }
        System.out.println(n+"的阶乘是"+sum);
    }
}

 

 

 

package test;

import java.util.Scanner;

public class test3 {
    public static void main(String args[]){
        //输入任意学生成绩,输入不合法提示错误,重新输入直到合法
        Scanner input = new Scanner(System.in);
        int n = 0;
        System.out.println("输入一个数");
        do{
            n = input.nextInt();
            if(n<0||n>100){
            System.out.println("输入错误,请重新输入");
            }
        }while(n<0||n>100);
        System.out.println("输入正确是"+n);
    }
}

 

 

package test;

public class test4 {
    public static void main(String args[]){
        //年薪3w,年增长率6%,计算10年后年薪,统计总收入
        double year = 30000;
        double sum = 0;
        double add = 0.06;
        double x = 1;
        for(int a = 1;a<=10;a++){
            x = add*year;
            year +=x;
            sum = sum+year;
        }
        System.out.println("十年后年薪是"+year+"十年总年薪是"+sum);
    }
}

 

package work;

import java.util.Scanner;

public class test {
    public static void main(String args[]) {
        //打印出所有的"水仙花数
        Scanner input = new Scanner(System.in);
        int a=0,b=0,c=0;
        int q=0,w=0,e=0;
        for(int x =100;x<1000;x++) {
            a=x/100;
            b=x%100/10;
            c=x%10;
            q=a;
            w=b;
            e=c;
        for(int y = 1;y<3;y++) {
            a*=q;
            b*=w;
            c*=e;    
        }
            if(a+b+c==x) {
                System.out.println(x);
            }
        }
    }
}

package work;

import java.util.Scanner;

public class test1 {
    public static void main(String args[]) {
        //输入年月日,判断这是这一年中的第几天
        Scanner input = new Scanner(System.in);
        int year, month, day;
        int sum;
        int []day1 = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
        int []day2 = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
        
        while (true) {
            sum = 0;
            year = 0;
            month = 0;
            day = 0;
            
            System.out.println("请输入年份");
            year = input.nextInt();
            System.out.println("请输入月份");
            month = input.nextInt();
            System.out.println("请输入日期");
            day = input.nextInt();
            
            if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) {
                for (int i = 0; i < month - 1; i++)
                    sum += day2[i];
            }
            else {
                for (int i = 0; i < month - 1; i++)
                    sum += day1[i];
            }
            sum += day;
            
            System.out.println("这一天是这一年的第" + sum + "天");
        }
    }
}

 

 

package work;

import java.util.Scanner;

public class test2 {
    public static void main(String args[]) {
        //由控制台输入一个4位整数,求将该数反转以后的数
        Scanner input=new Scanner(System.in);
          System.out.println("请输入一个整数:");
          int a=input.nextInt();
          while(a>0)
          {
           int b=a%10;
           a=a/10;
           System.out.print(b);
          }
    }
}
           

 

 

 

 

package test;

 

import java.util.Scanner;

 

public class test3 {

public static void main(String args[]){

//输入任意学生成绩,输入不合法提示错误,重新输入直到合法

Scanner input = new Scanner(System.in);

int n = 0;

System.out.println("输入一个数");

do{

n = input.nextInt();

if(n<0||n>100){

System.out.println("输入错误,请重新输入");

}

}while(n<0||n>100);

System.out.println("输入正确是"+n);

}

}

posted on 2021-04-07 20:39  魔幻的猫头鹰  阅读(23)  评论(0编辑  收藏  举报