java第四次作业

1.package Test2;

1.import java.util.Scanner;

public class Xiti1 {

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner input=new Scanner(System.in);
        System.out.println("输入一个年份");
        int x=input.nextInt();
        if (x%4==0&&x%100!=0||x%400==0) {
            System.out.println("这年是闰年");
            
        }else
      System.out.println("这年不是闰年");
    }

}
2.package zuoye1;

import java.util.Scanner;


    
    import java.util.Random;
    import java.util.Scanner;

    public class 作业1 {
        
        public static void main(String[] args) {
            // TODO Auto-generated method stub
            Scanner input=new Scanner(System.in);
            System.out.println("请输入卡号");
            int x=input.nextInt();
            int y;
            y=x/100%10;
           Random r=new Random();
           int z=r.nextInt(10);
           System.out.println("x");
           if (z==x) {
               System.out.println("您成为了幸运会员");
            
        } 
           else {
               System.out.println("您没成为幸运会员");

        } 
            
        }
           
        }

 


3.package Test2;

import java.util.Scanner;

public class Xiti3 {

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner input=new Scanner(System.in);
        System.out.println("输入一个数");
        int x=input.nextInt();
        int y;
       if (x>0) {
           System.out.println(y=x+3);
           }
       else if (x==0) {
           System.out.println(y=0);
        
    } 
       else if (x<0) {
           System.out.println(y=x*2-1);

    }
    }

 

4.package Test2;

import java.util.Scanner;

public class Xiti4 {

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner input=new Scanner(System.in);
        System.out.println("输入第一个数");
        int a=input.nextInt();
        System.out.println("输入第二个数");
        int b=input.nextInt();
        System.out.println("输入第三个数");
        int c=input.nextInt();    
        if (a+b>c||a+c>b||b+c>a) {
            System.out.println("能构成一个三角形");
            

}

        } else {
            System.out.println("不能构成三角形");

        }
    }

}

 

5.package zuoye1;

import java.util.Scanner;

public class Test1 {

    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();
         int day;
         switch (month) {
        case 4:
        case 6:
        case 9:
        case 11:
            System.out.println("该月有30天");
            break;
        case 2:
            if (year%4==0&&year%100!=0||year%400==0) {
                System.out.println("这月有29天");
                break;
            } else {
                System.out.println("这月有28天");
                break;                
}
            default:
                System.out.println("这月有31天");
                break;
        }

    }

}

 

 

 

6.package zuoye1;

import java.util.Scanner;

public class Test2 {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
         Scanner input=new Scanner(System.in);
         System.out.println("请输入您的成绩");
         int a=input.nextInt();
         switch (a/10) {
        case 10:
        case 9:System.out.println("成绩为A");break;
        case 8:System.out.println("成绩为B");break;
        case 7:System.out.println("成绩为C");break;
        case 6:System.out.println("成绩为D");break;
            

        default:
            System.out.println("成绩为E");
            break;
        }
        

    }

}

 

 

 

 

7.package zuoye1;

 

import java.util.Scanner;

 

public class Test3 {

 

public static void main(String[] args) {

// TODO Auto-generated method stub

         Scanner input=new Scanner(System.in);

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

         int shu=input.nextInt();

        if (shu%2==0) {

         System.out.println("这个数是偶数");

 

} else {

System.out.println("这个数是奇数");

 

}  

 

}

 

}

 

 

8.package zuoye1;

 

import java.util.Scanner;

 

public class Test4 {

 

public static void main(String[] args) {

// TODO Auto-generated method stub

         Scanner input=new Scanner(System.in);

         System.out.println("请输入一个变量x");

         int x=input.nextInt();

         if (x==1) {

          System.out.println("x=1");

           }

         else if(x==5) {

          System.out.println("x=5");

         }

         else if(x==10) {

          System.out.println("x=10");

         }

         else {

          System.out.println("x=none");

}

}

 

}

 

 

 

9.package zuoye1;

import java.util.Scanner;

public class Test5 {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
       Scanner input=new Scanner(System.in);
       System.out.println("输入一个数");
       int shu=input.nextInt();
       if (shu%5==0&&shu%6==0) {
           System.out.println("能被5和6整除");
           }
       else if(shu%5==0) {
           System.out.println("能被5整除");
       }
       else if(shu%6==0) {
           System.out.println("能被6整除");
       }
       else if(shu%5!=0&&shu%6!=0){
           System.out.println("不能被5和6整除");

    }

    }

}

 

 


 

 

 

posted @ 2021-03-28 22:01  徐涛%  阅读(46)  评论(0编辑  收藏  举报