zoukankan      html  css  js  c++  java
  • JAVA作业。

    1.

    package text;

    import java.util.Scanner;
    public class zuoye {

        public static void main(String[] args) {
            //1.输入一个年份,判断是不是闰年(可以被4整除但不能被100整除,或者能被400整除)
            System.out.println("请输入一个年份:");
            Scanner sc = new Scanner(System.in);
            int a = sc.nextInt();
            if ((a % 4 == 0 && a % 100 != 0) || (a % 400 == 0)) {
                System.out.println(a+"年是闰年");
            }else {
                System.out.println(a+"年不是闰年");
            }
        }
    }

     

     2.

    package text;

    import java.util.Scanner;
    public class zuoye {

        public static void main(String[] args) {
            //2.输入一个4位会员卡号 如果百位数字是3的倍数 输出幸运会员,否则就不是.
            System.out.print("请输入会员卡号:");
            Scanner sc = new Scanner(System.in);
            int a = sc.nextInt();
            if (a >= 1000 && a <=9999) {
                if(a / 100 % 10 % 3 == 0) {
                    System.out.println(a+"是幸运会员");
                }else {System.out.println(a+"不是幸运会员");}
            }else {System.out.println("您的输入有误");}
        }
    }

    3.

    package text;

    import java.util.Scanner;
    public class zuoye {
            public static void main(String[] args) {
                //已知函数 x 输出y x>0 (x+3) x=0 y=0 x<0 x*2-1
                Scanner sc = new Scanner(System.in);
                System.out.print("请输入x的值:");
                int x = sc.nextInt();
                int y;
                if(x > 0) {
                    y = x + 3;
                    System.out.println("y值为:"+y);
                }if(x < 0) {
                    y = x*2 - 1;
                    System.out.println("y值为:"+y);
                }if(x == 0){
                    y = 0;
                    System.out.println("y值为:"+y);
                }
                }
            }

    4.

    package text;

    import java.util.Scanner;
    public class zuoye {
        public static void main(String[] args) {
            //输入三个数 构成三角形;
            Scanner sc = new Scanner(System.in);
            System.out.print("请输入第一个数:");
            int a = sc.nextInt();
            System.out.print(" 请输入第二个数:");
            int b = sc.nextInt();
            System.out.print(" 请输入第三个数:");
            int c = sc.nextInt();
            if((a + b) >= c && (a + c) >= b && (b + c) >= a){
                System.out.println("可构成三角形");
            }else {
                System.out.println("不可以构成三角形");}
            }
            
            
        }

  • 相关阅读:
    IE下PNG透明图片fadeIn出现黑边的问题
    愿闻其翔记(一)
    简单的日期选择器
    HTML5 贪吃蛇
    HTML5小程序,变化的色彩
    HTML5 Canvas 基本图形画法
    帝国CMS实现一二级导航及其高亮
    php中json_decode()和json_encode()
    JavaScript重复元素处理
    JQuery在光标位置插入内容
  • 原文地址:https://www.cnblogs.com/Mfb-/p/12560898.html
Copyright © 2011-2022 走看看