CSE116的学习笔记-Lec#1:Scala基础语法
Lecture #1 9/2
授课时间:2020-09-02 13:50:00
Scala Basics
Hello Scala!
Example:
1 | package week1.basics |
package week1.basics
: define where this code lives.object Hello
: Objectsdef main{}
: Main Methodprintln("Hello Scala!")
: Print Line
Methods Variables
1 | package week1.basics |
input
: input valueDouble
: Data type
Usually no return
statements.
var
: Variables declaration
Conditionals
1 | package week1.basics |
val
: Values declared with val
cannot change, Reassignment causes an ERROR!"small"
: means return "small"
Lecture Question
Question
In a package named “lecture” create an object named “FirstObject” with a metho named “computeShippingCost” that takes a Double representing the weight of a package as a paramater and returns a Double representing the shipping cost of the package.
Ex:
The shipping cost is ($)5 + 0.25 per pound over 30
- Every package weighing 30 pounds or less will cost 5 to ship.
- Ex. A package weighting 31 pounds cost 5.25 to ship
- Ex. A package weighting 40 pounds cost 7.50 to ship
All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.
Comment
TwikooValine