- package com;
- /**
- * 比较2个数值的大小
- *
- * @author Administrator
- *
- */
- public class IfTest2 {
- public static void main(String[] args) {
- int x = 3;
- int y = 10; // 定义2个整型变量,x,y
- System.out.println("=======开始比较=======");
- if (x > y) {
- System.out.println("x比y大!");
- }
- if (x < y) {
- System.out.println("x小于y!");
- }
- if (x == y) {
- System.out.println("x等于y!");
- }
- System.out.println("=======比较完成=======");
-
- /**
- * if..else
- * 判断一个数是奇数还是偶灵敏
- */
- int m=11;
- if(m%2==0){
- System.out.println(m+"是偶数!");
- }else{
- System.out.println(m+"是奇数");
- }
- }
- }
复制代码
|
|