第三周作业(上机)

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

 1 import java.util.*;
 2 public class wyy {
 3 
 4     /**
 5      * @param args
 6      */
 7     public static void main(String[] args) {
 8         // TODO Auto-generated method stub
 9         Scanner input=new Scanner(System.in);
10         System.out.println("请输入月份:");
11         int month=input.nextInt();
12         if(month%4==0&&month%100!=0||month%400==0) {
13             System.out.println("是闰月");
14             }
15         else { 
16             System.out.println("不是闰月");
17         }
18     }
19 }

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

 1 import java.util.*;
 2 public class wyy {
 3 
 4     /**
 5      * @param args
 6      */
 7     public static void main(String[] args) {
 8         // TODO Auto-generated method stub
 9         Scanner input=new Scanner(System.in);
10         System.out.println("请输入四位的会员号:");
11         int member=input.nextInt();
12         switch(member%1000/100){
13         case 3:
14         case 6:
15         case 9:
16             System.out.println("幸运会员");break;
17             default:
18                 System.out.println("不是幸运会员");break;
19         }
20     }
21 }

 3.

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

                      x + 3   ( x > 0 )

               y =      0     ( x = 0 )

                      x2 –1  ( x < 0 )

import java.util.*;
public class wyy {

	/**
	 * @param args
	 */
	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;
		if(x>0)
			y=x+3;
		else if (x==0)
			y=0;
		else
			y=x*x-1;
		System.out.println("y的值是"+y);
	}
}

  

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

import java.util.*;
public class wyy {

    /**
     * @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();
        int b=input.nextInt();
        int c=input.nextInt();
        if(a+b>c&&a+c>b&&b+c>a)
            System.out.println("能构成三角形");
        else
            System.out.println("不能构成三角形");
    }
}

原文地址:https://www.cnblogs.com/WangYYY/p/12538965.html