Documentos de Académico
Documentos de Profesional
Documentos de Cultura
Declaring multiple variables at a time. We can only assign two values and not
more than that.
Declaring a function and calling it. Here, we wrote a function for the product of
two numbers. +c tells to include the value of c.
Defined a class Quadrilateral and an object Area based on the class. Classes
helps in code reusability. Based on the class Quadrilateral, we created an
object of square to find the area.
Simple if..else condition. Compared two variables using if..else to find which one
is greater.
Simple while loop example. Initialized a with 10 and print a+1 until a<50. So, it
prints from 10 to 49.
Passing command line arguments and comparing two numbers. Above screenshot
shows that we passed command line argument in one case and no command line
arguments in another case. We used if..else and args.length in this example.
Created two arrays and printed those using different ways. One of the ways
used in the example to print the arrays is using for loop. The mkString method
is defined on collections and is a method which joins the elements of the
collection with the provided string.
The above are some other ways to create lists. List object takes the range and
returns the list. Above example takes range from 1 to 50 (1,50) and another
example prints the list with a difference between the elements (1,50,2) =>
difference of 2. We can also create tuples with heterogeneous collection of
elements. As shown above, we can retrieve the elements in a tuple.
Assignment Question
object Assignment
println(i) //printing the list of numbers that are divisible by 7 using for loop
}
var len = list_7.length //finding and assigning the length of list_7 to len
println("\nThe number of numbers that are divisible by 7 is: " +len) //printing
the length of list of numbers that are divisible by 7
*The above Scala program prints a list of numbers from 1 to 100 and checks the
numbers that are divisible by 7 from the list and prints them. We also find how
many numbers in the list are divisible by 7.