scala语言示例

Scala var关键字 (Scala var keyword)

The var Keyword in scala is used to declare variables. As Scala does not require explicit declaration of data type of the variable, var keyword is used. The variable declared using the var keyword as mutable variables.

scala中var关键字用于声明变量。 由于Scala不需要显式声明变量的数据类型,因此使用var关键字 。 使用var关键字声明的变量为可变变量。

Mutable Variables are those variable whose value can be changed in the program, these are used when you need variables which are updated as per the logic of the program. Example of some mutable variables are counters, loop variables, sum, etc.

可变变量是可以在程序中更改其值的那些变量,当您需要根据程序逻辑进行更新的变量时,将使用这些变量。 某些可变变量的示例包括计数器,循环变量,总和等。

Syntax to define mutable variables in Scala using var keyword:

使用var关键字在Scala中定义可变变量的语法:

    var I = 102;
var H : string = "IncludeHelp";

Syntax explanation, in the first on we have declared a variable I using var keyword. This can be changed in future. The value is 102 so scala will itself make it an int type. In the second one we have explicitly declared the data type of the variable. This is a good practice and you know the limitation of the initialization. It declares the var H as a string using variable. The value will be strictly string and if we stored a number in it will be stored as a string.

语法说明,首先,我们使用var keyword声明了变量I。 将来可以更改。 值是102,因此scala本身会将其设置为int类型。 在第二篇文章中,我们明确声明了变量的数据类型。 这是一个好习惯,您知道初始化的局限性。 它使用变量将var H声明为字符串。 该值将严格为字符串,如果我们在其中存储了数字,则将其存储为字符串。

Using var keyword you can define variables of all data types in Scala. The value of variables declared using the var keyword can be changed at any point in the program.

使用var关键字,您可以在Scala中定义所有数据类型的变量。 使用var关键字声明的变量的值可以在程序的任何位置更改。

Scala程序演示var关键字示例 (Scala program to demonstrate example of var keyword)

// Program that displays usage of var keyword in Scala
object VarKeyword {def main(args: Array[String]) {var myVar = 52;//Variable Initialized with value 52
print("Value of my myVar =" + myVar + "\n")
myVar = myVar + 6; // Value changes to 52+6
print("Changed Value of myVar = " + myVar )
}
}

Output

输出量

Value of my myVar =52
Changed Value of myVar = 58

Example explanation:

示例说明:

The code displays use of var keyword in real world program. The variable myVar's value changes in the program.

该代码显示了在实际程序中var关键字的使用。 变量myVar的值在程序中更改。

翻译自: https://www.includehelp.com/scala/var-keyword-with-example-in-scala.aspx

scala语言示例

scala语言示例_var关键字与Scala中的示例相关推荐

  1. python关键字from_from关键字和Python中的示例

    Python from关键字 from是python中的一个关键字(区分大小写),用于从模块中导入特定部分,例如函数,类等. from关键字的语法from module_name import spe ...

  2. map写法 scala语言_(转)scala中map与flatMap浅析

    在函数式语言中,函数作为一等公民,可以在任何地方定义,在函数内或函数外,可以作为函数的参数和返回值,可以对函数进行组合.由于命令式编程语言也可以通过类似函数指针的方式来实现高阶函数,函数式的最主要的好 ...

  3. c语言atoll函数怎么用_C ++中带有示例的atoll()函数

    c语言atoll函数怎么用 C ++ Atoll()函数 (C++ atoll() function) atoll() function is a library function of cstdli ...

  4. 第四课 尚硅谷Scala语言学习-面向对象

    第四课 尚硅谷Scala语言学习-面向对象 文章目录 第四课 尚硅谷Scala语言学习-面向对象 第一节 Scala 包 1.1 包基本语法 1.2 包说明 1.3 包对象 1.4 导包说明 第二节 ...

  5. scala语言的底层是java实现的_Scala学习笔记一(与Java、Jvm的关系以及程序执行流程分析)...

    一.Scala语言与Java.Jvm的关系分析 Scala语言是马丁奥德斯基接触Java语言后,针对Java语言的特点,将函数式编程语言的特点融合到Java中,由此发明的.Scala语言和Java语言 ...

  6. Scala语言整理(一)

    与Java对比 语法对比 对比项 Java Scala 说明 标识符 / / 反引号括起来的字符也是标识符. 语句结束 分号(;) 分号(;)或者换行   包 package ... package ...

  7. Scala语言简介以及开发环境部署

    一.概述 1.1 为什么学习scala Spark就是使用Scala编写的,为了更好的学习Spark,需要掌握Scala这门语言 Spark的兴起,带动了Scala语言的发展 1.2 Scala与Ja ...

  8. Scala核心编程 第一章—Scala语言概述

    一.Scala语言解释 1.什么是Scala语言 Spark-新一代内存级大数据计算框架,是大数据的重要内容. Spark就是使用Scala编写的.因此为了更好的学习Spark, 需要掌握Scala这 ...

  9. scala语言示例_标有示例的Scala关键字

    scala语言示例 Scala | 任一关键字 (Scala | Either Keyword) Either is a container similar to the option which h ...

最新文章

  1. python类是实例的工厂_Python设计模式之工厂方法模式实例详解
  2. 视频与图像RGB/YUV格式详解
  3. Python爬虫神器pyppeteer
  4. 如何用 J-Link 来串口调试?
  5. 三年前端,面试思考(二)
  6. 【codevs1040】【01NOIPTG】统计单词个数,字符串的划分DP
  7. 阿里全盘调整组织架构意味着什么?| 畅言
  8. 201671010140. 2016-2017-2 《Java程序设计》java学习第十六周
  9. 怎么才能免费下载CSDN资源啊
  10. html模板导出pdf文件
  11. 买房税费大攻略!哪些费用必须交?
  12. 谷歌退出中国为360挑战百度创造了机会
  13. matlab求二阶电路图,MATLAB实验MATLAB数值计算:二阶电路时域研究
  14. java前后端技术栈
  15. layui,始终打开最后一页
  16. 华为S2300开启WEB管理
  17. 你以为这样写Java代码很6,但我看不懂
  18. html做一个京东搜索功能,连续动作:自动搜索关键词采集信息—以京东为例
  19. 如何使用谷歌地图和LightningChart创建地理空间地图图表?
  20. Node-red开发软PLC程序?

热门文章

  1. php实现标签云,php标签云的实现代码
  2. WEB前端大神之路之基础篇
  3. CSS布局的三个关键属性:float、position、display
  4. [译] Airbnb 在 React Native 上下的赌注(一):概述
  5. DRF url控制 解析器 响应器 版本控制 分页(常规分页,偏移分页,cursor游标分页)...
  6. GT sport赛道详解 - Dragon Trail | 龙之径
  7. (八)cmockery中的calculator和run_tests函数的注释代码
  8. unity中怎么在InspectorI面板加LOGO
  9. Oracle 查询历史数据(转帖)
  10. 开启和关闭wifi的代码段