0
点赞
收藏
分享

微信扫一扫

IfSample

天蓝Sea 2022-03-18 阅读 10


/**
* 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.
*
*
*
*/

}




为人:谦逊、激情、博学、审问、慎思、明辨、 笃行

学问:纸上得来终觉浅,绝知此事要躬行

为事:工欲善其事,必先利其器。

态度:道阻且长,行则将至;行而不辍,未来可期

转载请标注出处!


举报
0 条评论