• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
柘冉
博客园    首页    新随笔    联系   管理    订阅  订阅
第三周作业

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

import java.util.Scanner;
public class nmz1 {

    public static void main(String[]args) {
        // TODO Auto-generated method stub
    int year=2010;
    Scanner scan=new
            Scanner(System.in);
    System.out.println("输入一个年份:");
    if(scan.hasNext()){
        String str1=scan.next();
        try{
            year=Integer.parseInt(str1);
        }catch(NumberFormatException e){
            System.out.println("输入错误!");
        }
        if((year%4==0&&year%100!=0)||(year%400==0)){
            System.out.println(year+"是闰年");
        }
        else{
            System.out.println(year+"不是闰年");
        }
    }
    scan.close();
    }

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

import java.util.Scanner;
public class nmz1 {

    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%1000/100)%3==0){
            System.out.println("是幸运会员");
        }else{
            System.out.println("不是幸运会员");
        }
    }

}

3.已知函数,输入x的值,输出对应的y的值. x + 3 ( x > 0 ) y = 0 ( x = 0 ) x2 –1 ( x < 0 ) 

import java.util.Scanner;
public class nmz1 {

    public static void main(String[]args) {
        // TODO Auto-generated method stub
    System.out.println("请输入y的值:");
    Scanner input=new
            Scanner(System.in);
    float x=input.nextInt();
    float 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.Scanner;
public class nmz1 {

    public static void main(String[]args) {
        // TODO Auto-generated method stub
    System.out.println("请输入三角形的三条边:");
    Scanner input=new
            Scanner(System.in);
    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("Yes");
    }
    else{
        System.out.println("No");
    }
    }

}

 

posted on 2020-03-21 23:45  柘冉  阅读(115)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3