P5710 【深基3.例2】数的性质--Java

题目描述

一些数字可能拥有以下的性质:

    性质 1:是偶数;
    性质 2:大于 4 且不大于 12。

小A 喜欢这两个性质同时成立的数字;Uim 喜欢这至少符合其中一种性质的数字;八尾勇喜欢刚好有符合其中一个性质的数字;正妹喜欢不符合这两个性质的数字。
输入格式

输入一个数字 x(0≤x≤1000)x(0\le x \le 1000)x(0≤x≤1000)
输出格式

输出这 4 个人是否喜欢这个数字,如果喜欢则输出1,否则输出0,用空格分隔。
输入输出样例
输入 #1

12

输出 #1

1 1 0 0
import java.util.Scanner;
public class P5710 {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        System.out.print(A(n)+" "+B(n)+" "+C(n)+" "+D(n));
    }
    public static int A(int n){
        if(n%2==0&&n>4&&n<=12){
        return 1;
        }
        else{
            return 0;
        }
    }
    public static int B(int n){
          if(n%2==0||(n>4&&n<=12)){
           return 1;
        }
        else{
           return 0;
        }
    }
    public static int C(int n){
        if(n%2==0^(n>4&&n<=12)){
            return 1;
        }
        else{
            return 0;
        }
    }
    public static int D(int n){
        if(n%2!=0&&!(n>4&&n<=12)){
            return 1;
        }
        else{
            return 0;
        }
    }
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值