第三次作业


1.输入一个年份,判断是不是闰年(能被4整除但不能被100整除,或者能被400整除)


 

package mjm;
import java.util.Scanner;
public class ddd {

    public static void main(String[] args) {
        Scanner input=new Scanner(System.in);
        System.out.println("输入年份:");
        int year=input.nextInt();
        if(year%4==0&&year%100!=0||year%400==0){
            System.out.println(year+"年是闰年");
        }else{
            System.out.println(year+"年不是闰年");
        }
    }
}

 

 

2.输入一个4位会员卡号,如果百位数字是3的倍数,就输出是幸运会员,否则就输出不是.

 

package mjm;

import java.util.Scanner;
public class ddd {

    public static void main(String[] args) {
         
               System.out.println("请输入四位会员卡号");
               Scanner s = new Scanner(System.in);
               int card = s.nextInt();
               if (card >= 10000 || card < 1000)
               {
                   System.out.println("输入的位数不正确");
                   return;
               }
               int bai = card / 100 % 10;
               if (bai % 3 == 0)
               {
                   System.out.println("是幸运会员");
               }
               else
               {
                   System.out.println("不是幸运会员");
               }
           }
                     

            }

 

 
3.已知函数,输入x的值,输出对应的y的值.

package mjm;

import java.util.Scanner;
public class ddd {

     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();
            int y=0;
            if(x>0){
                y=x+3;
            }else if(x==0){
                y=0;
            }else{
                y=x*2-1;
            }
            System.out.println("y="+y);
             
        }
     
    }

 


 4.输入三个数,判断能否构成三角形(任意两边之和大于第三边)

 

package mjm;

import java.util.Scanner;
public class ddd {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        System.out.println("请输入三角形的三边(整数):");
        int a = input.nextInt(); 
        int b = input.nextInt();
        int c = input.nextInt();
        int d = a + b; 
        int e = a + c;
        int f = b + c;
        if(d > c && e > b && f > a) {
        System.out.println("能构成三角形");
        } else {
        System.out.println("不能构成三角形"); 
        } 
        }
        }

 

posted @ 2020-03-23 12:31  mjmmmmmua  阅读(170)  评论(0编辑  收藏  举报