scala char
Scala Char數據類型 (Scala Char Data Type)
Character (char) in Scala is a data type that is equivalent to 16-bit unsigned integer. The character data type stores a single character. It can be an alphabet, numbers, symbols, etc. The character takes 2 bytes while storing its literals.
Scala中的字符(char)是相當于16位無符號整數的數據類型。 字符數據類型存儲單個字符。 它可以是字母,數字,符號等。該字符在存儲其文字時占用2個字節。
When stored in memory, the character data type is stored as a Unicode number. This Unicode number is a unique unification number that is available for every character literal to be stored.
當存儲在內存中時, 字符數據類型將存儲為Unicode數字。 該Unicode編號是唯一的統一編號,可用于要存儲的每個字符文字。
The use of char data type is not mandatory in scala. You can use var or val keyword in Scala to initialize them.
在scala中,不是必須使用char數據類型 。 您可以在Scala中使用var或val關鍵字進行初始化。
Syntax to define char variable in Scala:
在Scala中定義char變量的語法:
//With data type
var variable_name : Char = 'I';
//Without data type
val variable_name = 'i';
Example code to show Char data type in Scala
在Scala中顯示Char數據類型的示例代碼
object MyClass {
def main(args: Array[String]) {
var ch = 'I';
println("The value of character ch is "+ch);
ch = 'H';
println("The changed value of character ch is " + ch);
}
}
Output
輸出量
The value of character ch is I
The changed value of character ch is H
Code logic:
代碼邏輯:
The above code is used to show initialization and operation on Scala char data type. The code initializes the value 'I' to a variable ch and then prints "The value of character ch is I". After that, it changes the value if ch from 'I' to 'H' and then again prints the changed value.
上面的代碼用于顯示Scala char數據類型的初始化和操作。 該代碼將值“ I”初始化為變量ch ,然后輸出“字符ch的值為I” 。 之后,如果ch從“ I”更改為“ H” ,它將更改值,然后再次打印更改后的值。
翻譯自: https://www.includehelp.com/scala/char-data-type-in-scala.aspx
scala char