scala char_Scala中的Char数据类型
scala char
Scala Char數(shù)據(jù)類型 (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)是相當(dāng)于16位無(wú)符號(hào)整數(shù)的數(shù)據(jù)類型。 字符數(shù)據(jù)類型存儲(chǔ)單個(gè)字符。 它可以是字母,數(shù)字,符號(hào)等。該字符在存儲(chǔ)其文字時(shí)占用2個(gè)字節(jié)。
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.
當(dāng)存儲(chǔ)在內(nèi)存中時(shí), 字符數(shù)據(jù)類型將存儲(chǔ)為Unicode數(shù)字。 該Unicode編號(hào)是唯一的統(tǒng)一編號(hào),可用于要存儲(chǔ)的每個(gè)字符文字。
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數(shù)據(jù)類型 。 您可以在Scala中使用var或val關(guān)鍵字進(jìn)行初始化。
Syntax to define char variable in Scala:
在Scala中定義char變量的語(yǔ)法:
//With data typevar variable_name : Char = 'I';//Without data typeval variable_name = 'i';Example code to show Char data type in Scala
在Scala中顯示Char數(shù)據(jù)類型的示例代碼
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 HCode 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數(shù)據(jù)類型的初始化和操作。 該代碼將值“ I”初始化為變量ch ,然后輸出“字符ch的值為I” 。 之后,如果ch從“ I”更改為“ H” ,它將更改值,然后再次打印更改后的值。
翻譯自: https://www.includehelp.com/scala/char-data-type-in-scala.aspx
scala char
總結(jié)
以上是生活随笔為你收集整理的scala char_Scala中的Char数据类型的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 请问现在淘宝上的二手笔记本联想T510加
- 下一篇: 《蜀四贤咏》第十五句是什么