/**PageBeginHtml Block Begin **/ /***自定义返回顶部小火箭***/ /*生成博客目录的JS 开始*/ /*生成博客目录的JS 结束*/

IfSample

/**
 * Java中的 if语句与其他所有语言中的F语句的工作方式类似。此外,语法也与C/CH+以及C#语言中的f语句完全相同。if语句最简单的形式如下所示:
 * if(condition) statement;
 * 
 * 其中,condition是布尔表达式。如果 condition为true,就执行该语句。如果condition为false,就绕过该语句。下面是一个例子:
 * if(num < 100)system.out.println ( "num is less than 100");
 * 在这个例子中,如果num包含的值小于100,那么条件表达式为true,因而会执行println()语句。如果num包含的值大于或等于100,将会绕过println()语句。
 * 
 * 在第4章将会看到,Java定义了完整的可以用于条件表达式的关系运算符,表2-1列举了其中的几个。
 * 
 * ==========================================
 *        java 中的 一些关系运算符
 * -------------------------------------------
 *  运算符                   含义
 *   <                      小于
 *   >                      大于
 *   ==                     等于
 *  ==========================================
 * 
 */
package com.alanliu.Java8BasicCodeStuding.Java8BasciCode.Unit2.Point4ControlStatement;

/***
 * Demonstrate the if.
 * 
 * Call this file "IfSample.java".
 */
class IfSample {
    public static void main(String args[]) {
        int x, y;

        x = 10;
        y = 20;

        if (x < y)
            System.out.println("x is less than y");

        x = x * 2;
        if (x == y)
            System.out.println("x now equal to y");

        x = x * 2;
        if (x > y)
            System.out.println("x now greater than y");

        // this won't display anything        
        if (x == y)
            System.out.println("you won't see this");
    }
    
    /**
     * 
     * 这个程序的输出如下表示:
     *     x is less than y
        x now equal to y
        x now greater than y

     * 在这个程序中需要注意的另外一点是:下面这行代码:
     *  int x, y;
     *  通过使用由逗号分隔的列表,声明了两个变量x和y.
     * 
     * 
     * 
     */
    
}

 

posted @ 2022-02-17 21:42  一品堂.技术学习笔记  阅读(57)  评论(0编辑  收藏  举报