java判断数的奇偶性_判断一个数的奇偶性
編寫一個程序可以實現(xiàn)檢測正負數(shù)的奇偶性。
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("輸入數(shù)據(jù): " + 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);
}
}
正數(shù)運行結(jié)果1:
please input a number:
12343252335
輸入數(shù)據(jù): 12343252335
12343252335 is odd
the min_value of Long is: -9223372036854775808
the max_value of Long is: 9223372036854775807
負數(shù)運行結(jié)果2:
please input a number:
-231441341
輸入數(shù)據(jù): -231441341
-231441341 is odd
the min_value of Long is: -9223372036854775808
the max_value of Long is: 9223372036854775807
總結(jié)
以上是生活随笔為你收集整理的java判断数的奇偶性_判断一个数的奇偶性的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 奥卡姆剃刀定律(Occam‘s Razo
- 下一篇: 包学会之浅入浅出Vue.js:升学篇