判断一个数的奇偶性

1
编写一个程序可以实现检测正负数的奇偶性。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package com.liaojianya.chapter1;
 
import java.util.Scanner;
 
/**
 * This program demonstrates the way of judge number is odd or even
 * @author LIAO JIANYA
 *
 */
public class OddEven
{
    @SuppressWarnings("resource")
    public static void main(String[] args)
    {
         
        Scanner scan = new Scanner(System.in);
        System.out.println("please input a number: ");
        long read = scan.nextLong();
        System.out.println("输入数据: " + read);
         
        if(read % 2 == 1 || read % 2 == -1)
        {
            System.out.println(read + " is odd");
        }
        else
        {
            System.out.println(read + " is even");
        }
         
        System.out.println("the min_value of Long is: " + Long.MIN_VALUE);
        System.out.println("the max_value of Long is: " + Long.MAX_VALUE);
    }
}

  正数运行结果1:

1
2
3
4
5
6
please input a number:
12343252335
输入数据: 12343252335
12343252335 is odd
the min_value of Long is: -9223372036854775808
the max_value of Long is: 9223372036854775807

  负数运行结果2:

1
2
3
4
5
6
please input a number:
-231441341
输入数据: -231441341
-231441341 is odd
the min_value of Long is: -9223372036854775808
the max_value of Long is: 9223372036854775807

  

posted @   Andya_net  阅读(743)  评论(0编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET10 - 预览版1新功能体验(一)
点击右上角即可分享
微信分享提示