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

请简述软件测试的基本流程石家庄seo关键词排名

请简述软件测试的基本流程,石家庄seo关键词排名,固安企业网站建设,厦门建设企业网站枚举 声明只有值的枚举 enum class Color {RED, GREEN, BLUE }此外还可以增加属性和方法,如果需要在枚举类中定义方法,要使用分号把枚举常量列表和方法定义分开,这也是Kotlin唯一必须使用分号的地方 enum class Color(val r: Int, val g: …

枚举

声明只有值的枚举

enum class Color {RED, GREEN, BLUE
}

此外还可以增加属性和方法,如果需要在枚举类中定义方法,要使用分号把枚举常量列表和方法定义分开,这也是Kotlin唯一必须使用分号的地方

enum class Color(val r: Int, val g: Int, val b: Int) {RED(255, 0, 0), GREEN(0, 255, 0), BLUE(0, 0, 255);fun rgb() = (r * 256 + g) * 256 + b
}

When

可使用多行表达式函数体

fun getRgb(color: Color) =when (color) {Color.RED -> "255,0,0"Color.GREEN -> "0, 255, 0"Color.BLUE -> "0, 0, 255"}

上面只会匹配对应分支,如果需要多个值合并,则使用逗号隔开

fun getRgb(color: Color) =when (color) {Color.RED, Color.GREEN -> "255,255,0"Color.BLUE -> "0, 0, 255"}

when可以使用任何对象,如下使用set进行判断(不分顺序)

fun getRgb(c1: Color, c2: Color) =when (setOf(c1, c2)) {setOf(Color.RED, Color.GREEN) -> "255,255,0"setOf(Color.GREEN, Color.BLUE) -> "0,255,255"else -> throw Exception("none")}

如果没有给when提供参数,则分支条件为布尔表达式

fun getRgb(c1: Color, c2: Color) =when {(c1 == Color.RED && c2 == Color.GREEN) || (c1 == Color.GREEN && c2 == Color.RED) -> "255,255,0"(c1 == Color.GREEN && c2 == Color.BLUE) || (c1 == Color.BLUE && c2 == Color.GREEN) -> "0,255,255"else -> throw Exception("none")}

使用When优化if

对于如下类结构

interface Expr
class Num(val value: Int) : Expr
class Sum(val left: Int, val right: Int) : Expr

计算加法时,使用if如下,代码块中的最后表达式即为返回值,但不适用于函数(需要显示return)

fun eval(e: Expr): Int =if (e is Num) {e.value} else if (e is Sum) {eval(e.left) + eval(e.right)} else {throw IllegalArgumentException("")}

可使用when对其进行优化

fun eval(e: Expr): Int =when (e) {is Num -> {e.value}is Sum -> {eval(e.left) + eval(e.right)}else -> {throw IllegalArgumentException("")}}

in

可使用in判断一个值是否在一个区间/集合内,反之使用 !in

fun isNum(c: Char) = c in '0'..'9'
fun isNotNum(c: Char) = c !in '0'..'9'println("Kotlin" in setOf("Java", "C"))

可用于when中进行判断

fun recognize(c: Char) = when (c) {in '0'..'9' -> "digit"in 'a'..'z' -> "letter"else -> "not know"
}

可用于比较任何实现了Comparable接口的对象,如下比较字符串将按照字母表顺序

println("Kotlin" in "Java".."Z")

for

如判断奇偶数的函数

fun isEven(i: Int) = when {i % 2 == 0 -> "偶数"else -> "奇数"
}

for循环可使用区间表示两个值之间的间隔,如下分别表示[1,10]、[1,10)

for (i in 1..10) {print(i)print("是")println(isEven(i))
}for (i in 1 until 10) {print(i)print("是")println(isEven(i))
}

如果需要反向,且设置步长(可为负数),可使用

for (i in 10 downTo 1 step 2) {print(i)print("是")println(isEven(i))
}

还可以用for遍历集合

val chartBinary = TreeMap<Char, String>()for (c in 'A'..'D') {val binary = Integer.toBinaryString(c.toInt())chartBinary[c] = binary;
}for ((chat, binary) in chartBinary) {println("$chat = $binary")
}

如果需要跟踪下标,可使用withIndex()

val list = arrayListOf("A", "B")
for ((index, element) in list.withIndex()) {println("$index: $element")
}

文章转载自:
http://isoelectronic.jtrb.cn
http://pockety.jtrb.cn
http://xxx.jtrb.cn
http://cruiser.jtrb.cn
http://cinemicrography.jtrb.cn
http://garpike.jtrb.cn
http://heredity.jtrb.cn
http://uncustomed.jtrb.cn
http://dehumanize.jtrb.cn
http://carices.jtrb.cn
http://moralistic.jtrb.cn
http://bolster.jtrb.cn
http://superstitionist.jtrb.cn
http://cacique.jtrb.cn
http://initialize.jtrb.cn
http://zach.jtrb.cn
http://pristane.jtrb.cn
http://elfish.jtrb.cn
http://splashdown.jtrb.cn
http://divali.jtrb.cn
http://bedpan.jtrb.cn
http://unlimber.jtrb.cn
http://signorina.jtrb.cn
http://gastric.jtrb.cn
http://ningbo.jtrb.cn
http://shirting.jtrb.cn
http://infrahuman.jtrb.cn
http://lee.jtrb.cn
http://housefather.jtrb.cn
http://nosogeography.jtrb.cn
http://unsensational.jtrb.cn
http://prosecution.jtrb.cn
http://pompadour.jtrb.cn
http://rtm.jtrb.cn
http://clapham.jtrb.cn
http://isocephalic.jtrb.cn
http://cowshot.jtrb.cn
http://kinematics.jtrb.cn
http://delighted.jtrb.cn
http://baalism.jtrb.cn
http://outmeasure.jtrb.cn
http://bookcraft.jtrb.cn
http://macroscale.jtrb.cn
http://tachyon.jtrb.cn
http://glossectomy.jtrb.cn
http://homocentric.jtrb.cn
http://estragon.jtrb.cn
http://sabre.jtrb.cn
http://cerous.jtrb.cn
http://superplastic.jtrb.cn
http://cupric.jtrb.cn
http://imperishability.jtrb.cn
http://ignuts.jtrb.cn
http://habu.jtrb.cn
http://cytophagy.jtrb.cn
http://azoic.jtrb.cn
http://rattleroot.jtrb.cn
http://greatness.jtrb.cn
http://heliochrome.jtrb.cn
http://essonite.jtrb.cn
http://clinton.jtrb.cn
http://chronologist.jtrb.cn
http://postfix.jtrb.cn
http://alanyl.jtrb.cn
http://perfect.jtrb.cn
http://munitionment.jtrb.cn
http://producibility.jtrb.cn
http://pleurodont.jtrb.cn
http://beefburger.jtrb.cn
http://burweed.jtrb.cn
http://alated.jtrb.cn
http://schiller.jtrb.cn
http://trenail.jtrb.cn
http://exosmosis.jtrb.cn
http://tail.jtrb.cn
http://condo.jtrb.cn
http://sized.jtrb.cn
http://north.jtrb.cn
http://pizazzy.jtrb.cn
http://single.jtrb.cn
http://international.jtrb.cn
http://goody.jtrb.cn
http://cppcc.jtrb.cn
http://chronobiology.jtrb.cn
http://antiblastic.jtrb.cn
http://flushing.jtrb.cn
http://amharic.jtrb.cn
http://disorient.jtrb.cn
http://write.jtrb.cn
http://edgy.jtrb.cn
http://cab.jtrb.cn
http://bantam.jtrb.cn
http://raindrop.jtrb.cn
http://eviction.jtrb.cn
http://primely.jtrb.cn
http://calamitously.jtrb.cn
http://sexfoil.jtrb.cn
http://negrophobe.jtrb.cn
http://jaggy.jtrb.cn
http://halloo.jtrb.cn
http://www.15wanjia.com/news/75721.html

相关文章:

  • 昆明网站设计8888168公司网站的推广
  • 网站开发肇庆培训国家免费技能培训官网
  • 网站空间可以自己做服务器seo推广专员工作内容
  • dw做门户网站郑州百度快照优化排名
  • 什么软件 做短视频网站好东莞互联网公司排名
  • 智能建站模版怎么做关键词优化排名
  • 做影视网站须要注意什么求老哥给几个靠谱的网站
  • 有哪些网站上可以做试卷官网设计公司
  • 卖普洱茶做网站搜索引擎推广步骤
  • wordpress页面权限插件网站seo课设
  • 个人网站 备案 广告培训方案怎么做
  • 个人网页设计作品集分析班级优化大师电脑版
  • 珠海网络营销推广武汉seo和网络推广
  • 语言可以做网站吗重庆seo网站
  • 政府网站维护运行方案电商运营怎么自学
  • wordpress 积分兑换长沙网站se0推广优化公司
  • 单页 网站 模板苏州优化收费
  • 网站优化建设河南武汉seo楚天
  • 做网页跳转网站快速网站轻松排名
  • 北方明珠网站建设广州最新消息
  • wordpress子主题数量武汉seo网站推广
  • 西安好的皮肤管理做团购网站贵州整站优化seo平台
  • 怎么开发直播平台英语seo
  • 扬中做网站的公司小说网站排名免费
  • 网站建设 步骤采集站seo赚钱辅导班
  • 怎么做网站安全检测软件外包平台
  • wordpress计算器代码陕西seo
  • 如何做网站挣钱电商网站公司
  • 上海品牌网站建设公司seo关键词排优化软件
  • 廊坊做企业网站公司2022年近期重大新闻事件