java强制变量声明语句_Java中声明语句的定义

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:

以下三个声明语句声明intbooleanString变量:

 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.

变量numberanotherNumberyetAnotherNumber都具有int数据类型。 两个布尔变量isFinishedisAlmostFinished分别声明为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强制变量声明语句

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值