基本程序 打印Scala的Hello World

Scala中的基本程序 (Basic program in Scala)

As your first Scala program, we will see a basic output program that just prints "Hello World" or any other similar type of string. With this example, we will see what are the part of the code that is important and why they are used?

作为您的第一个Scala程序 ,我们将看到一个基本的输出程序,该程序仅打印“ Hello World”或任何其他类似类型的字符串。 在此示例中,我们将看到重要的代码部分以及为什么使用它们?

So, the basic code to print Hello World in Scala is:

因此, 在Scala中打印Hello World基本代码是:

object MyClass {
def main(args: Array[String]) {
print("Hello World!");
}
}

Output

输出量

Hello World!

In this code, if you have observed there are three parts, the class definition, main() function and the print statement. We will discuss each of them in detail.

在这段代码中,如果您观察到了三部分,则是类定义, main()函数和print语句。 我们将详细讨论它们中的每一个。

object MyClass

对象MyClass

If you are familiar with object-oriented programming (especially java) you would know that every method needs a class for execution. So this is the main class defined in Scala. The main class is simply a class that contains the main() function. Here, we have named our main class MyClass. Now we will define a method named main in this class which will start execution when the code will run.

如果您熟悉面向对象的编程(尤其是Java),则将知道每个方法都需要一个用于执行的类。 因此,这是Scala中定义主要类主类只是包含main()函数的类 。 在这里,我们将主类命名为MyClass 。 现在,我们将在此类中定义一个名为main的方法,该方法将在代码运行时开始执行。

main() method

main()方法

In the main class (MyClass) there is defined as the main() method. Let's dig in the main() method defined in our code.

在主类( MyClass )中,将其定义为main()方法 。 让我们深入研究代码中定义的main()方法。

    def main(args: Array[String]) 

Now, if we see it like any normal method def is keyword used create the method.

现在,如果我们看到它像使用任何常规方法def是关键字一样,请创建该方法。

Next is the name of the method, in our case it is main() this tells the compiler that this method needs to be called first when the code is running.

接下来是方法的名称,在我们的例子中是main(),它告诉编译器在代码运行时需要首先调用此方法。

Then comes the set of parameters that are being passed to the method. Here, since the call is from the starting point i.e. there is no caller that can pass value it. Therefore, the parameters it takes can we 0, its variable parameters of a function. The parameters are passed in the function are called command-line arguments. These are passed as a string variable to the function. Then the main code that will run on the execution of the code is written in the main function.

然后是传递给该方法的参数集。 在这里,由于调用是从起点开始的,即没有调用者可以传递值。 因此,它需要的参数可以为0, 即函数的可变参数 。 在函数中传递的参数称为命令行参数。 这些作为字符串变量传递给函数。 然后,将在执行代码时运行的主要代码写入main函数中。

print() Method

print()方法

In the main() function here we have only one line of code that has a print method. The print() method take a string value as input and prints it on screen. You can add variables using the "+" sign that we will see in the next article.

main()函数中 ,只有一行代码具有打印方法。 print()方法将字符串值作为输入并将其打印在屏幕上。 您可以使用在下一篇文章中看到的“ +”号添加变量。

翻译自: https://www.includehelp.com/scala/basic-program-print-hello-world-in-scala.aspx

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

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

相关文章

java treemap lastkey_Java TreeMap lastKey()用法及代码示例

java.util.TreeMap.lastKey()用于检索Map中存在的最后一个或最高键。用法:tree_map.lastKey()参数:该方法不带任何参数。返回值:该方法返回映射中存在的最后一个键。异常:如果映射为空,则该方法将引发NoSuchElementException。以下…

mysql属于数据库三级模式_数据库系统的三级模式指的是什么

数据库系统的三级模式指的是什么发布时间:2020-10-26 10:11:21来源:亿速云阅读:52作者:小新小编给大家分享一下数据库系统的三级模式指的是什么,希望大家阅读完这篇文章后大所收获,下面让我们一起去探讨吧&…

《自顶向下网络设计(第3版)》——导读

目录 第1部分 辨明客户的需求和目标 第1章 分析商业目标和制约 1.1 采用自顶向下的网络设计方法 1.2 分析商业目标 1.3 分析商业制约 1.4 商业目标检查表 1.5 小结 1.6 复习题 1.7 设计环境 第2章 分析技术目标与折衷措施 2.1 可扩展性 2.2 可用性 2.3 网络性能 2.4 安全性 2…

python矩阵变化_用numpy改变矩阵的形状

我的问题有两个方面。我有下面的代码来处理一些矩阵。在import numpytupleList [(0, 122), (1, 246), (2, 157), (3, 166), (4, 315), (5, 108), (6, 172), (7, 20), (8, 173), (9, 38), (10, 28), (11, 72), (12, 102), (13, 277), (14, 318), (15, 316), (16, 283), (17, 31…

最小硬币问题_进行更改的最小硬币数量

最小硬币问题Description: 描述: This is classic dynamic programming problem to find minimum number of coins to make a change. This problem has been featured in interview rounds of Amazon, Morgan Stanley, Paytm, Samsung etc. 这是经典的动态编程问题…

java 生成xml乱码_jdom解决中文乱码问题 JAVA生成xml文件帮了我很大的忙

决解了数据库读取出来 再保存到xml 产生的乱码问题import java.io.FileOutputStream;import java.io.IOException;import java.io.OutputStreamWriter;import org.jdom.Attribute;import org.jdom.Document;import org.jdom.Element;import org.jdom.output.Format;import org.…

给定重量上限,背包问题_满足给定重量的袋子的最低成本

给定重量上限,背包问题Problem statement: 问题陈述: You are given a bag of size W kg and you are provided costs of packets different weights of oranges in array cost[] where cost[i] is basically cost of i kg packet of oranges. cost[i] -1 means t…

springMVC rest风格

1.dispatcherServlet的配置<!-- The front controller of this Spring Web application, responsible for handling all application requests --><servlet><servlet-name>springDispatcherServlet</servlet-name><servlet-class>org.springfram…

sql2008能否打开mysql数据库_mysql数据库数据能不能导入到sql server中

点“测试”按钮确认你的链接是正确的。 Press the "Test" button to ensure your connection settings are set properly and then the "OK" button when youre done.二. 创建Microsoft SQL到MySQL的链接1.在SQL Server Management Studio中打开一个new qu…

c语言 函数的参数传递示例_isunordered()函数与C ++中的示例

c语言 函数的参数传递示例C isunordered()函数 (C isunordered() function) isunordered() function is a library function of cmath header, it is used to check whether the given values are unordered (if one or both values are Not-A-Number (NaN)), then they are u…

java进一_JAVA小白进:基础入门知识

1.注释&#xff0c;关键字&#xff0c;标识符1.注释(1)注释&#xff1a;解释说明程序的而文字。(2)注释的分类&#xff1a;单行注释 格式&#xff1a; //注释的文字多行注释 格式&#xff1a;/*注释的文字*/文档注释 格式&#xff1a;/**注释的文字*/(3)注释的作用&#xff1a;…

补丁(patch)的制作与应用

为什么80%的码农都做不了架构师&#xff1f;>>> 转自http://linux-wiki.cn/wiki/zh-hans/%E8%A1%A5%E4%B8%81(patch)%E7%9A%84%E5%88%B6%E4%BD%9C%E4%B8%8E%E5%BA%94%E7%94%A8 如果hack了开源代码&#xff0c;为了方便分享&#xff08;如提交Bug&#xff09;或自己…

php知识点汇总与解答_PHP操作员能力倾向问题与解答

php知识点汇总与解答This section contains Aptitude Questions and Answers on PHP Operators. 本节包含有关PHP运算符的 Aptitude问答。 1) Which of the following types of operators are used in PHP? Arithmetic OperatorsLogical OperatorsArray OperatorsString Oper…

csv导入mysql phpmyadmin_【转】从phpMyAdmin批量导入Excel内容到MySQL(亲测非常简洁有效)...

今天做项目遇到需要用phpMyAdmin批量导入Excel内容到MySQL数据库。分析了我的踏坑经历并且总结一最便捷的一套导入数据的方法&#xff0c;非常实用简洁&#xff1a;1、修改Excel表的数据&#xff0c;使得Excel中的字段与数据库字段要一一对应&#xff0c;并加上自增id。2、然后…

weakhashmap_Java WeakHashMap putAll()方法与示例

weakhashmapWeakHashMap类的putAll()方法 (WeakHashMap Class putAll() method) putAll() method is available in java.util package. putAll()方法在java.util包中可用。 putAll() method is used to copy all of the associations or mappings from the given map and assig…

c语言memcmp和java的_C语言memcmp()函数:比较m字节长的两个字符串s1和s2

函数名&#xff1a;memcmp头文件&#xff1a;函数原型&#xff1a; void* memcmp(void *s1,void *s2,unsigned m);功能&#xff1a;比较m字节长的两个字符串s1和s2参数&#xff1a; s1 和 s2 为要比较的字符串unsigned m 为要比较的前m个字节返回值&#xff1a;s1s1s2 返回等…

[下载地址] Subclipse 1.10.9(SVN) _附说明

http://pan.baidu.com/s/1bp6EFHt转载于:https://www.cnblogs.com/gscq073240/articles/6814429.html

hbase 伪分布安装 java_HBase基础和伪分布式安装配置

一、HBase(NoSQL)的数据模型1.1 表(table)&#xff0c;是存储管理数据的。1.2 行键(row key)&#xff0c;类似于MySQL中的主键&#xff0c;行键是HBase表天然自带的&#xff0c;创建表时不需要指定1.3 列族(column family)&#xff0c;列的集合。一张表中有多个行健&#xff0c…

java treemap_Java TreeMap firstEntry()方法及示例

java treemapTreeMap类的firstEntry()方法 (TreeMap Class firstEntry() method) firstEntry() method is available in java.util package. firstEntry()方法在java.util包中可用。 firstEntry() method is used to retrieve the key-value pairs linked with the lowest valu…

linux常用网络命令ping和arping

linux常用网络命令ping和arping ping 向目标主机发送icmp请求包 常用来测试当前主机与目标主机网络连接状况 常见选项 -c 设置发包的个数 -s 设置发的包的块大小&#xff0c;最大不超过65507 -W 设置接收回应超时时间 -i …