zoukankan      html  css  js  c++  java
  • Scala数组练习(1)

    1、在Scala REPL中,计算3的平方根,然后再对该值求平方。现在,这个结果与3相差多少?

    scala>val a = 3
    val a:Int = 3
    
    //计算平方根
    scala>val aa = sqrt(a)
    val aa:Double = 1.7320508075688772
    
    //计算平方数
    scala> aa*aa
    val res0:Double = 2.9999999999999996
    
    //计算差值
    scala> a-res0
    val res1: Double =4.440892098500626E-16

    2 、Scala允许你用数字去乘一个字符串,去REPL中试一下"crazy"*3。这个操作做什么?

    //字符串叠加输出
    scala>"crazy"*3
    val res0: String = crazycrazycrazy

    3 、 10 max 2的含义是什么?max方法定义在哪个类中?

    scala>10 max 2
    val res0:Int = 10

    4、在Scala中如何获取字符串“Hello”的首字符和尾字符?

    //取hello字符串下表为0即首字符
    scala>“Hello". apply(0)
    val res0 : char=H
    
    scala>“Hello"(0)
    val res2: char=H
    
    //取hello字符串下表为4即尾字符
    scala>"Hello". apply(4)
    val res1:char=o
    
    scala>“Hello“(4)
    val res3 : char = o
  • 相关阅读:
    *Reverse Linked List II
    *Insertion Sort List
    Convert Sorted List to Binary Search Tree
    Reverse Integer
    read cache return null
    纳秒和随机数
    libthread_db
    gdb
    tls session resumption
    http://www.linux-commands-examples.com/xmllint
  • 原文地址:https://www.cnblogs.com/20190308-zlz/p/14532760.html
Copyright © 2011-2022 走看看