Scala山脉

Scala Range

Scala山脉

A Range is a bounded series with a uniform interval with an upper and lower limit. The range literal is a numerical sequence of number ranging with a certain limit.

范围是一个有上限且下限均匀的有界序列。 范围文字是具有一定限制的范围内的数字的数字序列。

This defined sequence has many uses in programming like in easy initialization of the loop, sequence problems, etc.

此定义的序列在编程中有许多用途,例如在循环的轻松初始化,序列问题等中。

Methods to initialize a range

初始化范围的方法

There are multiple methods by which a range variable can be initialized. They are,

有多种方法可以用来初始化范围变量。 他们是,

  1. By using "to" keyword

    通过使用“ to”关键字

    Syntax : var range_name = a to b 
    Example: var a = 3 to 6 // gives 3 , 4, 5, 6.
    
    
  2. By using "by" keyword with others: Increases the interval

    通过与其他用户一起使用“ by”关键字:增加间隔

    Syntax : var range_name =  a until b by x
    Example: var a = 3 until 10 by 2 // gives 3, 5, 7, 9.
    
    
  3. By using "range" keyword

    通过使用“范围”关键字

    Syntax : var range_name = range(a,b,x) 
    Example: var a = range(3,6,1)// gives 3 , 4, 5,6.
    
    

The range can also be directly initialized to a data structure like an array, list, vector, map. Methods to initialize range to an array:

范围也可以直接初始化为数据结构,例如数组,列表,向量,映射。 将范围初始化为数组的方法:

toarray Method

数组方法

var var_name = (2 to 6 ).toarray 

Using range method of array object

使用数组对象的范围方法

var var_name = Array.range(5 to 9)

In a similar way List and vector method works.

List和vector方法以类似的方式工作。

Sample code to illustrate use of Scala range

示例代码说明了Scala系列的用法

object myObject 
{ 
def rangeprint(a:Range){
println(a) 
println(a(1)) 
println(a.last) 
}
def main(args: Array[String]) 
{ 
val R1 = 3 to 6
val R2 = 3 until 7
var R3 = 3 to 11 by 2
var R4 = Range(3,45,4)
rangeprint(R1)
rangeprint(R2)	
rangeprint(R3)	
rangeprint(R4)
} 	
} 

Output

输出量

Range 3 to 6
4
6
Range 3 until 7
4
6
Range 3 to 11 by 2
5
11
inexact Range 3 until 45 by 4
7
43

翻译自: https://www.includehelp.com/scala/ranges-in-scala.aspx

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/543731.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

黑客经验谈:跳板攻击入侵技术实例解析

网络入侵,安全第一,一个高明的入侵者,不会冒然实行动. 他们在入侵时前会做足功课,入侵时会通过各种技术手段保护自己,以防被对方发现,引火烧身. 其中,跳板技术是攻击者通常采用的技术. 下面笔者结合实例&am…

dom属性和html属性_HTML属性

dom属性和html属性Attributes are used to provide additional information of a tag such as it’s alignments, color, size of the text and other. The attributes are given with the tag that is between the angular brackets after the tag name. The attributes have …

科普:UTF-8 GBK UTF8 GB2312 之间的区别和关系

UTF-8:Unicode TransformationFormat-8bit,允许含BOM,但通常不含BOM。是用以解决国际上字符的一种多字节编码,它对英文使用8位(即一个字节),中文使用24为(三个字节)来编码…

vue3实现本地开发使用的px转换成vw,px转换成rem方法整理

前言: 项目中如果想本地开发使用px,但是界面上线以后界面是自适应的效果,可以有多种方式来实现效果。 一、px转成vw 1、安装,安装成功后,node_modules 会新增这两个插件包 npm i postcss-px-to-viewport-8-plugin 2、新增 post…

airplay2协议是什么_什么是AirPlay?

airplay2协议是什么AirPlay (AirPlay) AirPlay is released by Apple in the year 2004. It allows the easy exchange of audios without the use of any wired technique between the two devices. It was previously termed as AirTunes and later got its name changed to …

微信支付开发(5) 订单查询

本文介绍微信支付中订单查询功能的实现。 作者:方倍工作室 地址:http://www.cnblogs.com/txw1958/p/wxpay-order-query.html 一、订单查询 因为某一方技术的原因,可能导致商户在预期时间内都收不到最终支付通知,此时商户可以通过该…

ruby 执行函数_Ruby at()函数

ruby 执行函数Ruby中的at()函数 (at() function in Ruby) If you are working with arrays in Ruby, sometimes you may need to find the element at a particular index. For meeting the purpose, we have got at() function in Ruby which is already defined in Rubys lib…

python饼形图_Python | 饼形图

python饼形图A pie plot or a pie chart is a circular statistical graphic technique, in which a circle is divided into slices with respect to numerical proportion. In a pie chart, the arc length, central angle, and area of each slice, is proportional to the …

Linux巡检

# uname -a # 查看内核/操作系统/CPU信息 # head -n 1 /etc/issue # 查看操作系统版本 # cat /proc/cpuinfo # 查看CPU信息 # hostname # 查看计算机名 # lspci -tv # 列出所有PCI设备 # lsusb -tv # 列出所有USB设备 # lsmod # 列出加载的内核模块 # env # 查看环境变量 # fre…

appweb ejs_EJS部分

appweb ejsHi! Welcome. Today, we are going to look at EJS partials. EJS Partials help us avoid repetition of the same code on several web pages. 嗨! 欢迎。 今天,我们将看EJS局​​部函数 。 EJS Partials帮助我们避免在多个网页上重复相同的…

Struts2配置

1. 设定server a) window– preferences – myeclipse – servers – tomcat – 6.x b) 选择tomcat homedirectory c) 选择enable d) finish 2. 设定jdk环境 a) window– preferences – java – installed jres b) 如果没有对应的JDK…

ruby继承_Ruby继承

ruby继承Ruby中的继承 (Inheritance in Ruby) Inheritance is a feature of Object Oriented languages in which new classes are derived from existing classes and resulting in the formation of a hierarchy of classes. The derived class is often called as child cla…

Spring与Hibernate整合中,使用OpenSessionInViewFilter后出现sessionFactory未注入问题

近期在知乎看到一句话,保持学习的有一种是你看到了很多其它的牛人,不甘心,真的不甘心。Spring和hibernate整合的时候,jsp页面做展现,发现展现属性出现: org.apache.jasper.JasperException: could not init…

sql判断数据库类型数据_SQL数据类型

sql判断数据库类型数据SQL | 资料类型 (SQL | Data Types) Just like other programming languages, facilities of defining data of various types are available in SQL also. SQL supports the following data types for the specification of various data-items or field…

同事反馈环:如何实现持续改进的文化

“魔镜魔镜告诉我,谁才是最美丽的人?”,邪恶的皇后如此问道。似乎在精益和敏捷企业中也会有很多与《白雪公主》中类似的问题,如果我们没有一面可以看到我们正在做什么的镜子,我们就很难搞清楚我们有多么美丽&#xff0…

Scala懒惰瓦尔

Scala | 懒惰的瓦尔 (Scala | lazy val) Scala programming language allows the user to initialize a variable as a lazy val. A lazy variable is used when we need to save memory overheads while object creation. Using the lazy keyword, you can halt the initializ…

经典功率谱估计及Matlab仿真

原文出自:http://www.cnblogs.com/jacklu/p/5140913.html 功率谱估计在分析平稳各态遍历随机信号频率成分领域被广泛使用,并且已被成功应用到雷达信号处理、故障诊断等实际工程中。本文给出了经典功率谱估计的几类方法,并通过Matlab的实验仿真…

ruby 三目运算符_Ruby运算符

ruby 三目运算符Ruby运算符 (Ruby operators) Operators are the symbols which assist compiler or interpreter to carry out certain mathematical, logical and relational tasks and produce the results. Operators are method calls with parameters. 运算符是帮助编译器…

极验验证码流程-3.图片加密处理 图片移位

终于把图片加密给搞定了,原理是他把图分成了52个部分,然后通过移动来形成新的图片 主要的位置关系看代码 顺便吐槽下ruby,小众语言就是这么不方便,很多库都没有,百度了半天 最后换成了java来写 图片保存到本地的就不详细说了 主要…

什么是Brouter?

代理:网络设备 (Brouter: A network device) Brouter is a network device, which operates as a combination of both bridge and router. In this single device, a user will get a function of both bridge and router, as it can send out data to create a co…