4章实践练习编写:1.Java程序,实现判断变量x是奇数还是偶数。

1.编写Java程序,实现判断变量x是奇数还是偶数。

import java.util.Scanner;

public class Demo {
	public Demo() {
		// TODO Auto-generated constructor stub
	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		if (x % 2 == 0)
			System.out.println(x + "是偶数");
		else
			System.out.println(x + "是奇数");

	}
}

 

你可能感兴趣的:(java)