Variables and Data Types in Scala

 Variables and Data Types in Scala


In Scala, variables can be defined using the var or val keywords. var defines a mutable variable, while val defines an immutable variable. Here's an example:

java


var x = 5

x = 10 // This is valid because 'x' is mutable


val y = "Hello, world!"

y = "Goodbye, world!" // This is invalid because 'y' is immutable

Scala supports several data types, including Int, Double, String, Boolean, and more. Here are a few examples:


kotlin


val num: Int = 42

val pi: Double = 3.14159

val name: String = "John"

val isTrue: Boolean = true

No comments:

Post a Comment

The Importance of Cybersecurity in the Digital Age

 The Importance of Cybersecurity in the Digital Age Introduction: In today's digital age, where technology is deeply intertwined with ev...