java强制变量声明语句
One kind of Java statement is a declaration statement, which is used to declare a variable by specifying its data type and name. Below are some examples of declaration statements.
一种Java 语句是声明语句,它用于通过指定变量的数据类型和名称来声明变量 。 以下是声明语句的一些示例。
A variable, in relation to Java programming, is a container that holds values used in a Java program. Instead of defining a value over and over, a variable that has a value attached to it can be defined. Since variables must be given an initial starting value, you can see how that works in the examples on this page.
与Java编程相关的变量是一个容器,其中包含Java程序中使用的值。 可以不用定义一遍又一遍的值,而可以定义一个附加了值的变量。 由于必须给变量一个初始起始值,因此您可以在此页面的示例中看到它的工作方式。
Java声明示例 ( Examples of Declarations in Java )
The following three declaration statements declare int, boolean and String variables:
以下三个声明语句声明int , boolean和String变量:
int number;
boolean isFinished;
boolean isFinished;
String welcomeMessage;
字符串welcomeMessage;
In addition to the data type and name, a declaration statement can initialize the variable with a value:
除数据类型和名称外,声明语句还可以使用以下值初始化变量:
int number = 10;
boolean isFinished = false;
boolean isFinished = false;
String welcomeMessage = "Hello!";
字符串welcomeMessage =“ Hello!”;
It's also possible to declare more than one variable of the same data type in one declaration statement:
还可以在一个声明语句中声明多个相同数据类型的变量:
int number, anotherNumber, yetAnotherNumber;
boolean isFinished = false, isAlmostFinished = true;
boolean isFinished = false,isAlmostFinished = true;
String welcomeMessage = "Hello!", farewellMessage;
字符串welcomeMessage =“ Hello!”,farewellMessage;
The variables number, anotherNumber, and yetAnotherNumber all have int data types. The two boolean variables isFinished and isAlmostFinished are declared with initial values of false and true respectively. Finally, the String variable welcomeMessage is assigned the String value of "Hello!", while the variable farewellMessage is simply declared as a String.
变量number , anotherNumber和yetAnotherNumber都具有int数据类型。 两个布尔变量isFinished和isAlmostFinished分别声明为false和true的初始值。 最后,为String变量welcomeMessage分配了字符串值“ Hello!”,而将farewellMessage变量简单声明为String。
There are also control flow statements in Java as well as expression statements.
Java中还有控制流语句以及表达式语句 。
翻译自: https://www.thoughtco.com/declaration-statement-2034076
java强制变量声明语句