Scala Learning Review (ii)----Scala function definition, Process control, and exception handling

Source: Internet
Author: User

Note: This study originates from: DT Big Data DreamWorks (public number: Dt_spark)


1.in the previous section we learned about Scala Hello World, specifically defining a function as follows:

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/70/40/wKiom1W1CI_DmfpAAAGAJtFJ734715.jpg "title=" 1.png " alt= "Wkiom1w1ci_dmfpaaagajtfj734715.jpg"/>

2.define a function without parameters, as follows:

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/70/3D/wKioL1W1CozyVPGcAAHe2HM7cVE046.jpg "title=" 2.png " alt= "Wkiol1w1cozyvpgcaahe2hm7cve046.jpg"/>

Operation Result:

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/70/40/wKiom1W1CLqB3E5yAADWrR3mpMw688.jpg "title=" 3.png " alt= "Wkiom1w1clqb3e5yaadwrr3mpmw688.jpg"/>

3.define a function with parameters, as follows:

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/70/3D/wKioL1W1CryBnphpAAGYqmG_WWc417.jpg "title=" 4.png " alt= "Wkiol1w1crybnphpaagyqmg_wwc417.jpg"/>4, Process Control

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/70/40/wKiom1W1COrAA4HTAAHQnWcf5ss640.jpg "title=" 5.png " alt= "Wkiom1w1coraa4htaahqnwcf5ss640.jpg"/> If the parameter is entered when running, the situation is as follows:

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/70/3D/wKioL1W1CwDDYLGNAAF_UKugmdk668.jpg "style=" float: none; "title=" 6-1.png "alt=" Wkiol1w1cwddylgnaaf_ukugmdk668.jpg "/>

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/70/3D/wKioL1W1CwXT_kJMAAKBh6HvmSk379.jpg "style=" float: none; "title=" 6-2.png "alt=" Wkiol1w1cwxt_kjmaakbh6hvmsk379.jpg "/>

Way two:

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/70/40/wKiom1W1CT6A6ujTAAIRFXx0Nfg892.jpg "title=" 7.png " alt= "Wkiom1w1ct6a6ujtaairfxx0nfg892.jpg"/> can also put functions directly into the output statement:

As follows:

println ( Span style= "Font-size:16px;font-family:consolas;color:rgb (204,120,50);" >if (!args.isempty) Args ( ) else Span style= "Font-size:16px;font-family:consolas;color:rgb (106,135,89);" > "Scala.txt"

5.for Loop

mode 1:

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/70/3D/wKioL1W1C1DyxVOUAAD8GzvPenE977.jpg "title=" 8-1. PNG "alt=" wkiol1w1c1dyxvouaad8gzvpene977.jpg "/> mode 2: (Lists all files in the current directory)

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/70/3D/wKioL1W1C2rzPkWfAAIYoPv3veI083.jpg "title=" 8-2. PNG "alt=" wkiol1w1c2rzpkwfaaiyopv3vei083.jpg "/>6, exception handling

Similar to Java, the exception is handled by Try,catch, but, unlikeScala, it uses a case to match a different exception, that is, in a catch can write many exceptions, as long as the first match succeeds, the following exception will not match.

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/70/3D/wKioL1W1C3mAzYFPAAFtkaa8B8U651.jpg "title=" 9.png " alt= "Wkiol1w1c3mazyfpaaftkaa8b8u651.jpg"/>



This article is from "My Heart Flying" blog, please make sure to keep this source http://10562836.blog.51cto.com/10552836/1678591

Scala Learning Review (ii)----Scala function definition, Process control, and exception handling

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.