scala 随机生成整数_如何在Scala中以整数形式获取当前年份?

scala 随机生成整数

In Scala programming language, there is an option for the programmer to use libraries of java because of its interoperability with java.

在Scala编程语言中,程序员可以选择使用Java库,因为它可以与Java互操作。

There are a few methods to extract the date of a program,

有几种方法可以提取程序的日期

1)Java 8年 (1) Java 8 Year)

The java.time.year library is used to get the value of the current year.

java.time.year库用于获取当前年份的值

Syntax:

句法:

val data_int = Year.now.getvalue

Program:

程序:

import java.time.Year
object MyClass {
def main(args: Array[String]) {
val year: Int = Year.now.getValue; 
printf(" "+year)
}
}

Output

输出量

2019

2)Java 8 localDate (2) Java 8 localDate )

The java.time.localDate library is used to get the current date and we can extract year also using its method.

java.time.localDate库用于获取当前日期 ,我们也可以使用其方法提取年份

Synatx:

Synatx:

val data_int = LocalDate.now.getvalue

Example:

例:

import java.time.LocalDate
object MyClass {
def main(args: Array[String]) {
val year: Int = LocalDate.now.getYear; 
printf(" "+year)
}
}

Output

输出量

2019

3)Java日历 (3) Java Calendar)

The java.util.calendar is used to to get calendar information using the getInstance method. And passing the Calendar.YEAR to it will return the value of Year.

java.util.calendar用于使用getInstance方法获取日历信息 。 并将Calendar.YEAR传递给它将返回Year的值。

Synatx:

Synatx:

val year = Calendar.getInstance.get(Calendar.YEAR)

Example:

例:

import java.util.Calendar
object MyClass {
def main(args: Array[String]) {
val year: Int = Calendar.getInstance.get(Calendar.YEAR); 
printf(" "+year)
}
}

Output

输出量

2019

翻译自: https://www.includehelp.com/scala/how-to-get-the-current-year-as-an-integer-in-scala.aspx

scala 随机生成整数

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

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

相关文章

转载:glut.h 与 stdlib.h中 的exit()重定义问题的解决

遇到的问题,来自:http://blog.sina.com.cn/s/blog_629c53bd0100f5li.html 出现: c:\codeprogram\microsoft visual studio 10.0\vc\include\stdlib.h(353): error C2381: “exit”: 重定义;__declspec(noreturn) 不同1> c:\pro…

括号配对问题(C++栈)

题目描述: 现在&#xff0c;有一行括号序列&#xff0c;请你检查这行括号是否配对。 输入描述: 第一行输入一个数N&#xff08;0<N<100&#xff09;,表示有N组测试数据。后面的N行输入多组输入数据&#xff0c;每组输入数据都是一个字符串S(S的长度小于10000&#xff0c;…

FreeRTOS---堆内存管理(一)

FreeRTOS的堆内存管理简介动态内存分配及其与 FreeRTOS 的相关性动态内存分配选项内存分配方案Heap_1heap_2Heap_3Heap_4设置heap_4的起始地址Heap_5vPortDefineHeapRegions()堆相关的函数xPortGetFreeHeapSizexPortGetMinimumEverFreeHeapSizeMalloc调用失败的Hook函数这篇文章…

python中生成随机整数_在Python中生成0到9之间的随机整数

python中生成随机整数Following are the few explanatory illustrations using different python modules, on how to generate random integers? Consider the scenario of generating the random numbers between 0 and 9 (both inclusive). 以下是使用不同的python模块的一…

愚人节恶搞网站谨防遭黑客攻击

金山毒霸云安全中心日前发出预警&#xff0c;在近期拦截的大量“挂马”、钓鱼等恶意网页中&#xff0c;与“愚人节”相关的&#xff0c;在近一周数量急剧增加。 愚人节将至&#xff0c;怎么整人好玩?近期许多恶搞网站、相关的网络论坛的流量不断攀升。金山毒霸云安全中心日前发…

JavaScript中的String()函数与示例

String()函数 (String() function) String() function is a predefined global function in JavaScript, it is used to convert an object to the string. String()函数是JavaScript中预定义的全局函数&#xff0c;用于将对象转换为字符串。 Example: 例&#xff1a; In thi…

ASCII码排序(C++)

题目描述: 输入三个字符&#xff08;可以重复&#xff09;后&#xff0c;按各字符的ASCII码从小到大的顺序输出这三个字符。 输入描述: 第一行输入一个数N,表示有N组测试数据。后面的N行输入多组数据&#xff0c;每组输入数据都是占一行&#xff0c;有三个字符组成&#xff0c;…

FreeRTOS--堆内存管理(二)

堆内存管理代码具体实现heap_1内存申请函数内存释放函数heap_2内存块内存堆初始化函数内存块插入函数内存申请函数判断是不是第一次申请内存开始分配内存内存释放函数heap_3heap_4内存堆初始化函数内存块插入函数heap_5上一篇文章说了FreeRTOS实现堆内存的原理&#xff0c;这一…

在查询的结果中添加自增列 两种方法

解决办法《一》&#xff1a; 在SQL Server数据库中表信息会用到Identity关键字来设置自增列。但是当有数据被删除的话&#xff0c;自增列就不连续了。如果想查询出这个表的信息&#xff0c;并添 加一列连续自增的ID&#xff0c;可用如下查询语句&#xff1a; SELECT Row_Nu…

一个非常简单的C#面试题

怎样实现对所有类可读但是在同一个assembly可写那&#xff1f; 答案&#xff1a; 同一个assembly namespace ClassLibrary1 { public class Class1 { public string Name { get; internal set; } } public class Class2 { public void GS() { Class1 cc new Class1(); cc.Name…

css中的node.js_在Node App中使用基本HTML,CSS和JavaScript

css中的node.jsYou may think this is not important, but it is!. As a beginner in node.js, most coding exercises are always server sided. 您可能认为这并不重要&#xff0c;但确实如此&#xff01; 作为node.js的初学者&#xff0c;大多数编码练习始终都是服务器端的。…

Binary String Matching(C++)

题目描述: Given two strings A and B, whose alphabet consist only ‘0’ and ‘1’. Your task is only to tell how many times does A appear as a substring of B? For example, the text string B is ‘1001110110’ while the pattern string A is ‘11’, you should…

由一次代码优化想到的Js 数据类型

引子&#xff1a; 上周三进行了代码优化&#xff0c;其中有一个很普遍的代码&#xff0c;例如&#xff1a; if(test "") {dothis();}else{dothat()} ----->可以简化为 !test ? dothis():dothat(); if(test "") {dothis()}     ----->可以简化为…

VisualStudio2019配置OpenCV

VisualStudio2019配置OpenCV配置0x01 准备0x02 配置系统环境0x03 复制文件0x04 配置VisualStudio2019测试配置 0x01 准备 下载opencv&#xff0c;官网地址&#xff1a;https://opencv.org/releases/# 下载之后&#xff0c;自行安装 0x02 配置系统环境 找到高级系统设置 …

转载 Javascript的IE和Firefox兼容性汇编

微软关于IE、Firefox、Opera和Safari的JavaScript兼容性研究曾经发表过一份草案,可以点击下载《JScript Deviations from ES3》 以下为网上的一些搜集和整理(FF代表Firefox) 集合类对象问题现有代码中存在许多 document.form.item("itemName") 这样的语句&#xff0c…

存储器间接寻址方式_8086微处理器的程序存储器寻址模式

存储器间接寻址方式The Program Memory Addressing mode is used in branch instructions. These branch instructions are instructions which are responsible for changing the regular flow of the instruction execution and shifting the control to some other location…

Servlet的配置

1&#xff0c;基本配置 <!-- Servlet类的配置 --><servlet><servlet-name>sq</servlet-name><servlet-class>beyond.servlet.QuickStartServlet</servlet-class></servlet><!-- Servlet的虚拟路径的配置 --> <servlet-mapp…

Asp.net页面生存周期

# 事件或方法 功能 描述   1 Init 事件 页面初始化 初始化设置。   2 LoadViewState 方法 加载视图状态 填充ViewState属性。   3 LoadPostData 方法 处理回发数据 处理传入窗体数据。   4 Load 事件 加载页面 页面控件初始化完成并反映了客户端的数据。   5 RaisePo…

你正确关闭WCF链接了吗?

通常情况下我们关闭一个WCF链接都是简单地写把ICommunicationObject.Close()方法&#xff0c;但是这个方法有个问题就是当调用发生异常时&#xff0c;Close()会发生次生的异常&#xff0c;导致链接不能正常关闭。如果当这种异常很多时&#xff0c;必然对系统的稳定性有很大的影…

Visual Studio进行linux远程开发

目录准备工作创建一个项目配置远程项目准备工作 查看linux IP地址 安装了工具 sudo apt-get install openssh-server g gdb make ninja-build rsync zip开启ssh服务&#xff1a; sudo service ssh startVS2019按装了linux功能&#xff0c;如果没有&#xff0c;找到Visual S…