当前位置: 首页 > news >正文

大理石在哪些网站做宣传免费wordpress主题内容怎么改

大理石在哪些网站做宣传,免费wordpress主题内容怎么改,wordpress 表单,前程无忧招聘网站标记怎么做1. 方法 在scala中的操作符都被当成方法存在#xff0c;比如说、-、*、/ 12就是1.(2)的调用#xff0c; 2.0 是doule类型#xff0c;强调用Int类型的写法为1.(2:Int) 1.1 方法的声明和使用 定义方法的语法#xff1a; def 方法名([变量#xff1a;变量类型#xff…1. 方法 在scala中的操作符都被当成方法存在比如说、-、*、/ 12就是1.(2)的调用 2.0 是doule类型强调用Int类型的写法为1.(2:Int) 1.1 方法的声明和使用 定义方法的语法 def 方法名([变量变量类型变量变量类型]):返回值类型{方法体} 其中 在scala 中方法里面的最后一个表达式的值就是方法的返回值不需要return 返回 示例 定义无参无返回值的方法 // 定义无参无返回值的方法 scala def say():Unit {println(say hello)} say: ()Unit scala say() say hello // 简化过程 scala def say():Unit {println(say hello)} say: ()Unit // 方法体有一个语句省略{} scala def say():Unit println(say hello) say: ()Unit // 方法返回值可以由方法体返回结果类型推测 scala def say() println(say hello) say: ()Unit // 方法形参列表是空 可省略() scala def say println(say hello) say: Unit scala say say hello scala say() console:13: error: Unit does not take parameterssay() // 带有返回值的方法 def add(a:Int, b:Int):Int{val c a b; return c} 定义带有有参有返回值方法 // 定义带有有参有返回值方法 scala def add(a:Int, b:Int):Int{val c a b; return c} add: (a: Int, b: Int)Int scala add(4,5) res8: Int 9 // 简化流程 scala def add(a:Int, b:Int):Int{val c a b; return c} add: (a: Int, b: Int)Int // scala 不建议用return返回方法结果默认最后一个就是方法的返回值 scala def add(a:Int, b:Int):Int{val c a b; c} add: (a: Int, b: Int)Int // 去掉中间变量c scala def add(a:Int, b:Int):Int{a b} add: (a: Int, b: Int)Int // 方法体有一个语句省略{} scala def add(a:Int, b:Int):Inta b add: (a: Int, b: Int)Int // 方法返回值可以由方法体返回结果类型推测 scala def add(a:Int, b:Int)a b add: (a: Int, b: Int)Int scala add(4,5) res9: Int 9 方法的调用 object M1 {def say(name:String) {println(ssay ${name})}def add(a:Int, b:Int) a bdef main(args: Array[String]): Unit {// 普通调用M1.say(hainiu)// 中缀方法调用M1 say hainiu// 大括号调用当只有一个入参时才能用M1 say {hainiu}M1.add(4,5)// 中缀方法调用M1 add (4,5)} } 递归方法必须加返回值类型 scala def calculate(number:Int):Int {| if(number 1)| 1| else| number*calculate(number-1)| } calculate: (number: Int)Intscala calculate(5) res14: Int 120//文件夹递归方式查询def listFiles(path:String):Unit {val file new File(path)if(file.isFile){println(file.getPath)}else{println(file.getPath)val list file.list()for(p-list){listFiles(path/p)}}} 可变参数 scala def sum(x:Int*){| var sum 0| for(i-x)| sum i| sum| } sum: (x: Int*)Intscala sum(1,2,3) res15: Int 6scala sum(1,2,3,4,5) res16: Int 15scala def sum(x:Int,y:Int*){| var sum 0| for(i-y)| sum i| x * sum| } sum: (x: Int, y: Int*)Intscala sum(2,1,2,3) 2. 函数 在 java 中方法和函数是一个意思在 scala 中方法和函数是两种含义。 方法属于类或对象的成员 函数是对象 在 scala 中函数是一等公民。可以在任何地方定义在函数内或函数外可以作为函数的参数和返回值函数还可以赋给变量。 函数声明 val 变量名:[变量类型1,变量类型2 函数体返回类型 ] ([变量变量类型变量变量类型]) 函数体 示例 // 函数本身是没有名字的--匿名函数 // function2 是 函数有 两个输入参数 和 一个输出 本例是 两个Int输入一个Int输出 scala (a:Int, b:Int) a b res10: (Int, Int) Int function2 scala res10(4,5) res11: Int 9 // 把匿名函数赋给变量这个变量名称就成了函数名称 scala val add:(Int,Int)Int (a:Int, b:Int) a b add: (Int, Int) Int function2 scala add(4,5) res12: Int 9 函数的结果做为方法的参数 示例 // 定义周长函数 val perimeter (a:Int,b:Int) (ab) *2 // 定义面积函数 val area (a:Int, b:Int) a*b // 定义求和方法 def add(a:Int, b:Int) ab // 计算长方形周长和面积的和 println(add(perimeter(4,5), area(4,5))) 函数作为参数和返回值 scala add2 res22: (Int, Int) Int $Lambda$1133/80147637359919f37scala val add add2 add: (Int, Int) Int $Lambda$1133/80147637359919f37scala add(100,200) res23: Int 300scala def calculate(x:Int,y:Int) xy calculate: (x: Int, y: Int)Intscala def calculate(x:Int,y:Int,f:(Int,Int)Int) f(x,y) calculate: (x: Int, y: Int, f: (Int, Int) Int)Intscala calculate(10,20,add) res24: Int 30scala def sub(a:Int,b:Int) a-b sub: (a: Int, b: Int)Intscala val sub (a:Int,b:Int) a-b sub: (Int, Int) Int $Lambda$1137/1087688958784ceacbscala calculate(1,2,sub) res25: Int -1scala def getFunc() {| val func (x:Int,y:Int) xy| func| } getFunc: ()(Int, Int) Intscala getFunc()(1,2) res26: Int 3scala def getFunc(a:Int,b:Int) {| val func (x:Int) a*x b| func| } getFunc: (a: Int, b: Int)Int Intscala getFunc(2,1)(10) res27: Int 21 匿名函数 scala def calculate(x:Int,y:Int) xy calculate: (x: Int, y: Int)Intscala def calculate(x:Int,y:Int,f:(Int,Int)Int) f(x,y) calculate: (x: Int, y: Int, f: (Int, Int) Int)Intscala val add (x:Int,y:Int) xy add: (Int, Int) Int $Lambda$1044/98932130177049094scala calculate(10,20,add) res9: Int 30scala calculate(10,20,(x:Int,y:Int) xy) res10: Int 30scala (x:Int,y:Int) xy res11: (Int, Int) Int $Lambda$1068/1578712821106c988scala res11(200,300) res12: Int 500scala calculate(10,20,(x,y)xy) res13: Int 30scala (x,y) xy console:1: error: ; expected but found.(x,y) xy^ 方法转换成函数 1用空格下划线的方式 # 定义方法def add_def(a:Int,b:Int) a b# 方法转函数用空格下划线的方式val add_func add_def空格_ 2也可以把方法当参数使用这也因为scala会隐式的把方法转换成函数但并不是直接支持方法当参数的模式只是做了隐式的转换这种函数的转换分两种显示用空格_和隐式的这也体现了scala灵活的地方。 cala def add(x:Int,y:Int) xy add: (x: Int, y: Int)Intscala add console:13: error: missing argument list for method add Unapplied methods are only converted to functions when a function type is expected. You can make this conversion explicit by writing add _ or add(_,_) instead of add.add^ scala add _ res16: (Int, Int) Int $Lambda$1076/287628665335cdd2scala calculate(1,2,add _) res17: Int 3scala calculate(1,2,add) res18: Int 3
http://www.w-s-a.com/news/85051/

相关文章:

  • 像网站的ppt怎么做的移动app与网站建设的区别
  • 怎么建个人网站网站收录有什么用
  • 广州市医院网站建设广州头条新闻最近一周
  • 广州移动 网站设计中国交通建设监理协网站
  • 甘肃省第八建设集团公司网站wordpress topnews
  • 公司网站建设维保协议wordpress会员可看
  • 合肥百度网站排名优化深圳集团网站开发公司
  • 可以直接打开网站的方法手机回收站
  • 山西免费网站制作中天建设集团有限公司第九建设公司
  • 好的网站有哪些企业微信开发者工具
  • 网站通栏代码老外做的中国汉字网站
  • 东莞公司建站哪个更便宜wordpress宝塔伪静态
  • 六安网站建设价格做网站好吗
  • 中小企业网站建设咨询湖南省邵阳建设局网站
  • 分类网站一天做几条合适南安网络推广
  • 案例学 网页设计与网站建设百度竞价关键词出价技巧
  • 做公司网站要那些资料南雄网站建设
  • 自己做的网站发布到网上视频播放不了网页游戏奥奇传说
  • 网站效果用什么软件做品牌网站建设等高端服务
  • 四川省成华区建设局网站网站专业制作
  • 网站建设如何开票网站后台怎么做超链接
  • 教育网站设计方案建设网站技术公司电话号码
  • 建网站要定制还是第三方系统传奇网站模板psd
  • 免费搭建企业网站什么叫网站定位
  • 网站建设cms程序员培训班
  • 网站seo技术wordpress editor ios
  • 红酒网站设计成立公司需要哪些手续
  • 广州做网站哪个好网站建网站建设网站站网站
  • 如何快速提升网站pr短剧个人主页简介模板
  • 上海网站建设 永灿百度权重3的网站值多少