查看scala变量数据类型_Scala文字,变量和数据类型| Scala编程教程

查看scala变量数据类型

1)Scala数据类型 (1) Scala Data Types)

Scala has the same set of data types as in Java. The traditional 14 data types are inherited as it is in Scala.

Scala具有与Java中相同的数据类型集。 传统的14种数据类型在Scala中被继承。

The Following are Valid Data Types in Scala.

以下是Scala中的有效数据类型。

S. No. Data TypeBit Size Range
1Byte8-128 to 127
2Short 16-32768 to 32767
3Int32-2147483648 to 2147483647
4Long 64-9223372036854775808 to 9223372036854775807
5Float 32IEEE 754 single-precision
6Double 64IEEE 754 double-precision
7Char 16Unicode : U+0000 to U+FFFF
8String *Char Sequence
9Boolean1true/ false
10Unit*No Value
11Null*Null / empty reference
12Nothing*Subtype, includes no value
13Any*any object
14AnyRef*reference type
序号 数据类型 位大小 范围
1个 字节 8 -128至127
2 16 -32768至32767
3 整数 32 -2147483648至2147483647
4 64 -9223372036854775808至9223372036854775807
5 浮动 32 IEEE 754单精度
6 64 IEEE 754双精度
7 烧焦 16 Unicode:U + 0000至U + FFFF
8 *字符序列
9 布尔型 1个 真假
10 单元 *没有价值
11 空值 *空/空参考
12 没有 *子类型,不包含任何值
13 任何 *任何物体
14 任何参考 *参考类型

2)Scala中的文字 (2) Literals in Scala)

A literal is a value that can be assigned to a variable. Literals are basic constants that are assigned to the variable.

文字是可以分配给变量的值。 文字是分配给变量的基本常量。

Types of literals

文字类型

  • Integer Literals: Literals of type int or type Long. Integer literals can be declared using suffix L or I.

    整数文字 :int类型或Long类型的文字。 整数文字可以使用后缀L或I声明。

    Example:
    Decimal Literal : var i = 10L
    Hexadecimal Literal : var I = 0xFFF

  • Float Literals: Literals of type float or type double. They use Suffix f/F for float and D/d for double.

    Float字面量 :float或double类型的字面量。 他们将后缀f / F用于浮点,将D / d用于双精度。

  •     Example:
        Float Literal : var i = 12.35f
        Double Literal : var I = 123.5445d
    
    
  • Character Literals: Unicode characters like 'f'

    字符字面量 :Unicode字符,例如“ f”

  • String Literal: Multiple character literal like 'Include'

    字符串文字 :多字符文字,例如“包含”

  • Multi-Line Literal: Muti-line string Literal.

    多行文字 :多行字符串Literal。

  •     Example:
        "Include Help
        is of the best 
        Programming tutor"
    
    
  • Boolean: A literal with any of two values, True/False.

    布尔值 :具有两个值True / False的文字。

  • 3)Scala中的变量 (3) Variables in Scala)

    A variable is some space in the memory that stores values. The memory space allocated to the variable is based on its data type.

    变量是内存中存储值的一些空间。 分配给变量的内存空间基于其数据类型。

    Declaration of variables in Scala

    在Scala中声明变量

    In Scala, there are two types of variables 1) mutable (just like normal variables whose values can be changed during program execution) and 2) immutable (just like a constant whose value cannot be changed during program execution).

    在Scala中,有两种类型的变量:1) 可变的 (就像在程序执行过程中可以更改其值的普通变量一样)和2) 不可变的 (就像在程序执行过程中其值不能更改的常量一样)。

    Mutable variables are declared by using the "var" keyword, and immutable variables are declared by using the "val" keyword.

    可变变量使用“ var”关键字声明,不可变变量使用“ val”关键字声明

    Example:

    例:

        var I = 23 // this value can be changed
        val H = 12 //this value cannot be changed. 
    
    

    Although variable data type is detected by Scala but you can explicitly define it.

    尽管Scala检测到可变数据类型,但是您可以显式定义它。

        var I : string = "Include"
        val H : string = "Help"
    
    
    

    翻译自: https://www.includehelp.com/scala/literal-variables-and-data-type.aspx

    查看scala变量数据类型

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值