基本程序 打印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.pswp.cn/news/541452.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/541452.shtml
英文地址,請注明出處:http://en.pswp.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 …