日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

java判断数的奇偶性_判断一个数的奇偶性

發布時間:2023/12/16 49 豆豆
生活随笔 收集整理的這篇文章主要介紹了 java判断数的奇偶性_判断一个数的奇偶性 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

編寫一個程序可以實現檢測正負數的奇偶性。

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:

please input a number:

12343252335

輸入數據: 12343252335

12343252335 is odd

the min_value of Long is: -9223372036854775808

the max_value of Long is: 9223372036854775807

負數運行結果2:

please input a number:

-231441341

輸入數據: -231441341

-231441341 is odd

the min_value of Long is: -9223372036854775808

the max_value of Long is: 9223372036854775807

總結

以上是生活随笔為你收集整理的java判断数的奇偶性_判断一个数的奇偶性的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。