progs/lecture1.scala
changeset 23 8ac886bb0c15
parent 21 610f7a4a9ede
child 25 6253f4681451
equal deleted inserted replaced
22:9830203b058d 23:8ac886bb0c15
    18 (1 to 10).toList
    18 (1 to 10).toList
    19 
    19 
    20 (1 until 10).toList
    20 (1 until 10).toList
    21 
    21 
    22 // an element in a list
    22 // an element in a list
    23 List(1,2,3,1)(0)
    23 List(1, 2, 3, 1)(0)
    24 List(1,2,3,1)(3)
    24 List(1, 2, 3, 1)(3)
    25 
    25 
       
    26 1::2::3::Nil
       
    27 List(1, 2, 3) ::: List(4, 5, 6)
    26 
    28 
    27 //**Printing/Strings**
    29 //**Printing/Strings**
    28 //====================
    30 //====================
    29 
    31 
    30 println("test")
    32 println("test")
    50 1.toDouble
    52 1.toDouble
    51 
    53 
    52 //**Types**
    54 //**Types**
    53 //=========
    55 //=========
    54 
    56 
    55 // Int, Long, BigInt
    57 // Int, Long, BigInt, Float, Double
    56 // String, Char
    58 // String, Char
    57 // List[Int], Set[Double]
    59 // List[Int], Set[Double]
    58 // Pairs: (Int, String)        
    60 // Pairs: (Int, String)        
    59 // List[(BigInt, String)]
    61 // List[(BigInt, String)]
    60 
    62 
    61 
    63 
    62 //**Smart Strings**
    64 //**Smart Strings**
    63 //=================
    65 //=================
    64 """ """
    66 println(">\n<")
       
    67 println(""">\n<""")
       
    68 
       
    69 /* in Java
       
    70 val lyrics = "Baa, Baa, Black Sheep \n" +
       
    71              "Have you any wool? \n" +
       
    72              "Yes, sir, yes sir \n" +
       
    73              "Three bags full"
       
    74 */ 
       
    75 
       
    76 val lyrics = """Baa, Baa, Black Sheep  
       
    77                 |Have you any wool?
       
    78                 |Yes, sir, yes sir
       
    79                 |Three bags full""".stripMargin
       
    80 
       
    81 println(lyrics)
       
    82 
    65 
    83 
    66 //**Pairs/Tuples**
    84 //**Pairs/Tuples**
    67 //================
    85 //================
    68 
    86 
    69 val p = (1, "one")
    87 val p = (1, "one")