progs/lecture1.scala
changeset 21 610f7a4a9ede
parent 18 87e55eb309ed
child 23 8ac886bb0c15
equal deleted inserted replaced
20:07860dd35c2b 21:610f7a4a9ede
     1 
     1 // Lecture 1
     2 // webpages
     2 //==========
     3 
       
     4 
     3 
     5 //**Assignments (values)**
     4 //**Assignments (values)**
     6 //(variable names should be lower case)
     5 //(variable names should be lower case)
     7 //=====================================
     6 //=====================================
       
     7 
     8 val x = 42
     8 val x = 42
     9 val y = 3 + 4
     9 val y = 3 + 4
    10 
    10 
    11 
    11 
    12 //**Collections**
    12 //**Collections**
    37 
    37 
    38 println(lst.toString)
    38 println(lst.toString)
    39 println(lst.mkString("\n"))
    39 println(lst.mkString("\n"))
    40 
    40 
    41 // some methods take more than one argument
    41 // some methods take more than one argument
    42 println(lst.mkString("[",",","]"))
    42 println(lst.mkString("[", ",", "]"))
    43 
    43 
    44 //**Conversion methods**
    44 //**Conversion methods**
    45 //======================
    45 //======================
    46 
    46 
    47 List(1,2,3,1).toString
    47 List(1,2,3,1).toString
    75 
    75 
    76 //**Function Definitions**
    76 //**Function Definitions**
    77 //========================
    77 //========================
    78 
    78 
    79 def square(x: Int): Int = x * x
    79 def square(x: Int): Int = x * x
       
    80 
       
    81 
       
    82 
    80 
    83 
    81 //**Ifs control structures**
    84 //**Ifs control structures**
    82 //==========================
    85 //==========================
    83 
    86 
    84 def fact(n: Int): Int = 
    87 def fact(n: Int): Int = 
   114 for (n <- (1 to 10).toList; m <- (1 to 10).toList) yield m * n
   117 for (n <- (1 to 10).toList; m <- (1 to 10).toList) yield m * n
   115 
   118 
   116 val mtable = for (n <- (1 to 10).toList; m <- (1 to 10).toList) yield m * n
   119 val mtable = for (n <- (1 to 10).toList; m <- (1 to 10).toList) yield m * n
   117 
   120 
   118 mtable.sliding(10,10).toList.mkString(
   121 mtable.sliding(10,10).toList.mkString(
       
   122 
       
   123 
       
   124 // webpages