需求:任意给出一个整数,使用程序判定该整数是奇数还是偶数,并在控制台输出。
1 import java.util.Scanner; 2 3 public class Main { 4 public static void main(String[] args) { 5 Scanner sc = new Scanner(System.in); 6 System.out.println("please input a number:"); 7 int number = sc.nextInt(); 8 9 if(number % 2 == 0){ 10 System.out.println(number + "是偶数。。。"); 11 }else{ 12 System.out.println(number + "是奇数。。。"); 13 } 14 } 15 }
结果:
标签:奇偶,Java,Scanner,number,System,判定,005,println,out From: https://www.cnblogs.com/yiqiesuifeng/p/17697954.html