The unary_-() method is utilized to give the negation value of the stated character.
Method Definition: def unary_-: Int
Return Type: It returns negative Integer value of the stated character.
Example: 1#
// Scala program of unary_-() // method // Creating object object GfG
{ // Main method
def main(args : Array[String])
{
// Applying unary_- method
val result = '9' .unary _ -
// Displays output
println(result)
}
} |
Output:
-57
Example: 2#
// Scala program of unary_-() // method // Creating object object GfG
{ // Main method
def main(args : Array[String])
{
// Applying unary_- method
val result = 'A' .unary _ -
// Displays output
println(result)
}
} |
Output:
-65