1.scala shell命令

scala> :help
All commands can be abbreviated, e.g., :he instead of :help.
:edit <id>|<line> edit history
:help [command] print this summary or command-specific help
:history [num] show the history (optional num is commands to show)
:h? <string> search the history
:imports [name name ...] show import history, identifying sources of names
:implicits [-v] show the implicits in scope
:javap <path|class> disassemble a file or class name
:line <id>|<line> place line(s) at the end of history
:load <path> interpret lines in a file
:paste [-raw] [path] enter paste mode or paste a file
:power enable power user mode
:quit exit the interpreter
:replay [options] reset the repl and replay all previous commands
:require <path> add a jar to the classpath
:reset [options] reset the repl to its initial state, forgetting all session entries
:save <path> save replayable session to a file
:sh <command line> run a shell command (result is implicitly => List[String])
:settings <options> update compiler options, if possible; see reset
:silent disable/enable automatic printing of results
:type [-v] <expr> display the type of an expression without evaluating it
:kind [-v] <expr> display the kind of expression's type
:warnings show the suppressed warnings from the most recent line which had any

2.scala基本类型

3.常用特殊字符

\n 换行符,其Unicode编码为 (\u000A) 
\b 回退符,其Unicode编码为 (\u0008) 
\t tab制表符 ,其Unicode编码(\u0009) 
\” 双引号,其Unicode编码为 (\u0022) 
\’ 单引号,其Unicode编码为 (\u0027) 
\ 反斜杆,其Unicode编码为(\u005C)

4.函数

5.类

//采用关键字class定义

class Person {

//类成员必须初始化,否则会报错

//这里定义的是一个公有成员

var name:String=null

}

附录:

import java.sql.{ Connection, DriverManager }
import java.util.{Date, Locale}
import java.text.DateFormat
import java.text.DateFormat._
object Mysql extends App {
// def main(args: Array[String]): Unit = {
// 访问本地MySQL服务器,通过3306端口访问mysql数据库
val url = "jdbc:mysql://localhost:3306/mysql"
//驱动名称
val driver = "com.mysql.jdbc.Driver"
//用户名
val username = "root"
//密码
val password = "1"
//初始化数据连接
var connection: Connection = _
try {
//注册Driver
Class.forName(driver)
//得到连接
connection = DriverManager.getConnection(url, username, password)
val statement = connection.createStatement
//执行查询语句,并返回结果
val rs = statement.executeQuery("SELECT host, user FROM user")
//打印返回结果
while (rs.next) {
val host = rs.getString("host")
val user = rs.getString("user")
println("host = %s, user = %s".format(host, user))
}
} catch {
case e: Exception => e.printStackTrace
}
//关闭连接,释放资源
connection.close
//for循环
var myArray: Array[String] = new Array[String](10);
for (i <- 0 until myArray.length) {
myArray(i) = "value is: " + i;
}
for (value: String <- myArray) {
println(value);
}
for (value: String <- myArray if value.endsWith("5")) {
println(value);
}
val now = new Date
val df = getDateInstance(LONG, Locale.FRANCE)
println(df format now)
//}
val greetStrings =new Array[String](3)
greetStrings(0)="Hello"
greetStrings(1)=","
greetStrings(2)="world!\n"
greetStrings.update(0,"Hello")
greetStrings.update(1,",")
greetStrings.update(2,"world!\n")
for(i <- 0 to 2)
print(greetStrings(i))
val oneTwo = List(1,2)
val threeFour = List(3,4)
val oneTwoThreeFour=oneTwo ::: threeFour
println (oneTwo + " and " + threeFour + " were not mutated.")
println ("Thus, " + oneTwoThreeFour + " is a new list")
//几种循环
def printArgs ( args: Array[String]) : Unit ={
var i=0
while (i < args.length) {
println (args(i))
i+=1
}
}
def printArgs1 ( args: Array[String]) : Unit ={
for( arg <- args)
println(arg)
}
def printArgs2 ( args: Array[String]) : Unit ={
args.foreach(println)
}
//类与对象
class ChecksumAccumulator{
private var sum=0
def add(b:Byte) :Unit = sum +=b
def checksum() : Int = ~ (sum & 0xFF) +1
}
def gcdLoop (x: Long, y:Long) : Long ={
var a=x
var b=y
while( a!=0) {
var temp=a
a=b % a
b = temp
}
b
}
}

  

最新文章

  1. 解锁scott用户及设置密码
  2. docker 报错Failed to start Docker Storage Setup. 的处理基本都是容器满了
  3. unity, 顶点对齐
  4. [iOS基础控件 - 3.5] NSBundle, UIImageView和UIButton的区别, 模拟器和文档
  5. ASP怎样获得代码中第一张图片地址
  6. Keil 代码折叠功能的使用
  7. .a静态库的注意事项
  8. Linux安装oracle报错解决
  9. Ubuntu下安装Mysql并使用
  10. ARM异常---一个DataAbort的触发过程:
  11. xml的生成和发送
  12. ubuntu16.04编译安装imu_tk
  13. 384. Shuffle an Array(java,数组全排列,然后随机取)
  14. Sed 静默替换文件内容 以及 awk 的简单使用
  15. go语言之进阶篇error接口应用
  16. Robot framework(RF)学习基础
  17. 最小生成树(模板 prim)
  18. 启明星会议室预定系统Outlook版开始支持Exchange2013与Office365版
  19. micro:bit 软件生态系统介绍
  20. Java并发(2):Lock

热门文章

  1. [BZOJ4082][Wf2014]Surveillance[倍增]
  2. DelayQueue 订单限时支付实例
  3. 重磅发布丨乐维监控:全面兼容云平台,助力企业DevOps转型升级!
  4. 机器学习初入门04 – Seaborn(持续更新)
  5. maven util 类 添加 service
  6. Daily Scrum NO.5
  7. 从苦逼到牛逼,详解Linux运维工程师的打怪升级之路
  8. C++ STL 整理
  9. MySql的相关资操作
  10. C# 汉字排序