您的位置 首页 java

《Java面向对象程序设计》——语句(1)

《Java面向对象程序设计》——语句(1)

今天继续为大家带来《Java面向对象程序设计》的学习。

今天的主要内容是语句概述,条件分支语句,开关语句。

Today we continue to bring you the study of Java Object Oriented Programming.

Today’s main topics are statement overview, conditional branch statements, and switch statements.

01

语句概述

Java 中的语句可分为以下6类。

(1)方法调用语句。例如:System.out.println(“Hello”);

(2)表达式语句。表达式语句指由一个表达式构成一个语句,即在表达式尾加上 分号 。例如: 赋值语句 :x=23;

(3)复合语句。在Java中,可以用{ }把一些语句括起来构成复合语句。

例如:{z=123+x;

System.out.println(“How are you”);

}

(4)空语句。一个分号也是一条语句,称为空语句。

(5)控制语句。控制语句分为条件分支语句,开关语句和循环语句3种类型。

(6) package 语句和 import 语句。package语句和import语句和类,对象有关。

The statements in Java can be divided into the following six categories.

(1) Method call statements. For example: System.out.println(“Hello”);

(2) Expression statements. An expression statement is a statement consisting of an expression, i.e., a semicolon at the end of the expression. For example, the assignment statement: x=23.

(3) Compound statements. In Java, you can use { } to enclose some statements to form a compound statement.

For example: {z=123+x;

System.out.println(“How are you”);

}

(4) Empty statements. A semicolon is also a statement, called an empty statement.

(5) Control statements. There are three types of control statements: conditional branch statements, switch statements and loop statements.

(6) package statements and import statements. package statements and import statements are related to classes and objects.

02

条件分支语句

《Java面向对象程序设计》——语句(1)

条件分支语句按照语法格式分为以下三种形式。

(1) if 语句

if语句是单分支语句,即根据一个条件来控制程序执行的流程。

(2)if-else

if-else语句是单条件分支语句,即根据一个条件来控制程序执行的流程。

(3)if-else if-else语句

if-else if-else语句是多条件分支语句,即根据多个条件来控制程序执行的流程。

Conditional branching statements are divided into the following three forms according to the syntax format.

(1) if statement

The if statement is a single-branch statement that controls the flow of program execution based on a single condition.

(2) if-else

The if-else statement is a single conditional branch statement, which controls the flow of program execution based on a single condition.

(3) if-else if-else statement

The if-else if-else statement is a multi-conditional branching statement, which controls the flow of program execution based on multiple conditions.

03

开关语句

《Java面向对象程序设计》——语句(1)

switch语句是单条件多分支的开关语句。在switch语句中,”表达式“的值和”常量“的值必须是 byte , short ,int,char型或枚举类型常量,而且互不相同。switch语句首先计算表达式的值,如果表达式的值和某个case后面的常量值相等,就执行该case中的若干语句,直到碰到 break 语句为止。若switch语句中的表达式的值不与任何case的常量值相等,则执行default后面的若干个语句。

The switch statement is a single conditional multi-branch switch statement. In a switch statement, the value of an expression and the value of a constant must be byte, short, int, char , or enumerated constants, and they are not the same. If the value of the expression is equal to the value of a constant after a case, it executes a number of statements in that case until it hits a break statement. If the value of the expression in the switch statement is not equal to the value of the constant in any case, then several statements after default are executed.

参考资料:文字:百度;图片:微博;翻译:百度翻译

本文由LearningYard新学苑原创,部分图片文字来自网络,如有侵权请联系。

文章来源:智云一二三科技

文章标题:《Java面向对象程序设计》——语句(1)

文章地址:https://www.zhihuclub.com/195266.shtml

关于作者: 智云科技

热门文章

网站地图