SlideShare a Scribd company logo
1 of 28
This work is licensed under the Apache 2.0 License
Compose Camp
Android Basics with Compose:
Unit 1
Nishant Khandhar
Compose Camp is a hands-on introduction to
learning how you can build Android apps with
Jetpack Compose.
This work is licensed under the Apache 2.0 License
What is Compose Camp?
● Basic computer literacy
● Basic math skills
● Computer & headphones
● Internet connection
● Android Studio
This work is licensed under the Apache 2.0 License
Prerequisites
● Build your first Android apps
● Set up Android Studio on your computer
● Learn the basics of the Kotlin programming language
● Learn Jetpack Compose
● Discover resources to continue learning
This work is licensed under the Apache 2.0 License
Compose Camp Learning Objectives
This work is licensed under the Apache 2.0 License
INDEX
1. Introduction to Kotlin Playground.
2. Variables and Data types.
3. Functions in Kotlin.
4. Quiz
Kotlin Playground
This work is licensed under the Apache 2.0 License
Write and run Kotlin code in
the browser.
In computer programming, there's the
concept of a variable, which is a
container for a single piece of data.
You can envision it as a box that
contains a value. The box has a label,
which is the name of the variable. By
referring to the box by its name, you
have access to the value it holds.
This work is licensed under the Apache 2.0 License
Variables
years old
Variable
s
name age
My name is $name,and I am $age
This work is licensed under the Apache 2.0 License
“ALEX” 20
Variable
s
Name value: Meghan
Age value: 28
Output:
My name is Meghan and
I am 28 years old
Name value: Janet
Age value: 49
Output:
My name is Janet and I
am 49 years old
name age
My name is and I am years old
This work is licensed under the Apache 2.0 License
Basic data types
This work is licensed under the Apache 2.0 License
Kotlin Data type What kind of data it can contain Example literal values
String Text
“Add contact”
“Search”
Int Whole integer number
32
-59873
Double Decimal number
2.0
-37123.9999
Float
Decimal number (less precise than a Double).
Has an f or F at the end of the number.
5.0f
-1630.209f
Boolean
true or false. Use this data type when there
are only two possible values.
true
false
val keyword
This work is licensed under the Apache 2.0 License
Use when you expect the variable value will
not change.
Example: name
var keyword
Use when you expect the variable value can
change.
Example: age
Defining a variable
Use the assignment operator (=) to
assign a value to a variable either
during declaration of the variable or
updating the variable.
Defining a variable
Variables start with a var or
val
keyword.
fun main() {
val name: String = "Meghan"
var age: Int = 28
}
This work is licensed under the Apache 2.0 License
Defining a variable
All variables must have a name.
fun main() {
val name: String = "Meghan"
var age: Int = 28
}
This work is licensed under the Apache 2.0 License
Defining a variable
Data type is the type of data
that the variable holds.
fun main() {
val name: String = "Meghan"
var age: Int = 28
}
This work is licensed under the Apache 2.0 License
Defining a variable
The initial value is the value that
is stored in the variable.
fun main() {
val name: String = "Meghan"
var age: Int = 28
}
This work is licensed under the Apache 2.0 License
Functions
A function is a segment of a program that
performs a specific task.
You can have many functions in your program
or only a single one.
The main() function doesn’t actually get called
anywhere in your code; the Kotlin compiler uses
it as a starting point.
Defining a function
Functions begin with the fun
keyword followed by
function name and
parentheses and curly
braces.
fun namer () {
}
This work is licensed under the Apache 2.0 License
fun main() {
println(“Hello World”)
}
fun helloWorld () {
}
Defining a function
Functions have a name so that
they can be called.
fun displayIntroduction() {
}
This work is licensed under the Apache 2.0 License
fun helloWorld () {
println(“Happy Birthday, Alex”)
println(“You are now 20 years old”)
}
Defining a function
Functions need a set of parentheses
after the function name in order to
surround the function inputs.
This work is licensed under the Apache 2.0 License
Defining a function
The curly braces make up the
function body and contain the
instructions needed to execute
a task.
fun displayIntroduction() {
}
This work is licensed under the Apache 2.0 License
Putting it together
fun displayIntroduction() {
// We will fill this out!
}
This work is licensed under the Apache 2.0 License
Output:
Hi I’m Meghan and I am 28 years old
Putting it together
This work is licensed under the Apache 2.0 License
fun displayIntroduction() {
val name : String = "Meghan"
val age : Int = 28
println("Hi I'm $name and I am $age years old")
}
Putting it together
This work is licensed under the Apache 2.0 License
fun main() {
displayIntroduction()
}
fun displayIntroduction() {
val name : String = "Meghan"
val age : Int = 28
println("Hi I'm $name and I am $age years old")
}
Output:
Hi I’m Meghan and I am 28 years old
Returning in a function
We can return an output from a
function as per its defined output
datatype.
fun displayIntroduction() : String {
return “HelloWorld”;
}
This work is licensed under the Apache 2.0 License
Parameters of a function
We can pass extra information into
a function via parameters which
are declared between the
parentheses.
fun add(n1 : Int, n2 : Int) {
return n1 + n2
}
This work is licensed under the Apache 2.0 License
Parameters of a function
These parameters can also have
default values.
fun add(n1 : Int = 0, n2 : Int = 0) {
return n1 + n2
}
This work is licensed under the Apache 2.0 License
Arguments of a function
While calling a function in another
function, the values we pass to the
parameters defined are known as
Arguments.
fun main() {
var a : Int = 2
var b : Int = 3
println(add(a, b))
}
This work is licensed under the Apache 2.0 License
Work on Unit 1, Pathway 1
This work is licensed under the Apache 2.0 License
Have a Question? Just ask

More Related Content

Similar to Compose Camp - Unit 1 (1).pptx

Compose Camp - Intro.pdf.pdf
Compose Camp - Intro.pdf.pdfCompose Camp - Intro.pdf.pdf
Compose Camp - Intro.pdf.pdfKrishnaSoni261334
 
Compose_camp_Day_1.pptx
Compose_camp_Day_1.pptxCompose_camp_Day_1.pptx
Compose_camp_Day_1.pptxGanpatParmar1
 
Compose Camp Slide Session 1
Compose Camp Slide Session 1Compose Camp Slide Session 1
Compose Camp Slide Session 1AkshatBajpai12
 
Compose Camp S1.pptx
Compose Camp S1.pptxCompose Camp S1.pptx
Compose Camp S1.pptxGDSCSIT
 
-Kotlin_Camp_Unit2.pptx
-Kotlin_Camp_Unit2.pptx-Kotlin_Camp_Unit2.pptx
-Kotlin_Camp_Unit2.pptxRishiGandhi19
 
Compose Camp: Introduction to Kotlin.pptx
Compose Camp: Introduction to Kotlin.pptxCompose Camp: Introduction to Kotlin.pptx
Compose Camp: Introduction to Kotlin.pptxAmruthasriAmaravati
 
Session-1 edited.pptx
Session-1 edited.pptxSession-1 edited.pptx
Session-1 edited.pptxscienceTech11
 
Compose camp 2.pptx
Compose camp 2.pptxCompose camp 2.pptx
Compose camp 2.pptxbcedsc
 
GDSC_day_1.pptx
GDSC_day_1.pptxGDSC_day_1.pptx
GDSC_day_1.pptxGDSCICOER
 
Day3New GDSC.pptx
Day3New GDSC.pptxDay3New GDSC.pptx
Day3New GDSC.pptxGDSCICOER
 
Android Development | Compose camp day 3 | GDSC SEC Sasaram.pdf
Android Development | Compose camp day 3 | GDSC SEC Sasaram.pdfAndroid Development | Compose camp day 3 | GDSC SEC Sasaram.pdf
Android Development | Compose camp day 3 | GDSC SEC Sasaram.pdfShivamShrey1
 

Similar to Compose Camp - Unit 1 (1).pptx (20)

Kotlin Fundamentals.pptx
Kotlin Fundamentals.pptxKotlin Fundamentals.pptx
Kotlin Fundamentals.pptx
 
Compose Camp - Intro.pdf.pdf
Compose Camp - Intro.pdf.pdfCompose Camp - Intro.pdf.pdf
Compose Camp - Intro.pdf.pdf
 
Compose Camp #1.pptx
Compose  Camp #1.pptxCompose  Camp #1.pptx
Compose Camp #1.pptx
 
Compose_camp_Day_1.pptx
Compose_camp_Day_1.pptxCompose_camp_Day_1.pptx
Compose_camp_Day_1.pptx
 
Compose Camp Slide Session 1
Compose Camp Slide Session 1Compose Camp Slide Session 1
Compose Camp Slide Session 1
 
Compose Camp - Session1.pdf
Compose Camp - Session1.pdfCompose Camp - Session1.pdf
Compose Camp - Session1.pdf
 
Compose Camp S1.pptx
Compose Camp S1.pptxCompose Camp S1.pptx
Compose Camp S1.pptx
 
Compose Camp 2.pdf
Compose Camp 2.pdfCompose Camp 2.pdf
Compose Camp 2.pdf
 
Compose Camp.pdf
Compose Camp.pdfCompose Camp.pdf
Compose Camp.pdf
 
-Kotlin_Camp_Unit2.pptx
-Kotlin_Camp_Unit2.pptx-Kotlin_Camp_Unit2.pptx
-Kotlin_Camp_Unit2.pptx
 
-Kotlin Camp Unit2.pptx
-Kotlin Camp Unit2.pptx-Kotlin Camp Unit2.pptx
-Kotlin Camp Unit2.pptx
 
Compose Camp: Introduction to Kotlin.pptx
Compose Camp: Introduction to Kotlin.pptxCompose Camp: Introduction to Kotlin.pptx
Compose Camp: Introduction to Kotlin.pptx
 
Compose Camp Session 1.pdf
Compose Camp Session 1.pdfCompose Camp Session 1.pdf
Compose Camp Session 1.pdf
 
Session-1.pptx
Session-1.pptxSession-1.pptx
Session-1.pptx
 
Session-1 edited.pptx
Session-1 edited.pptxSession-1 edited.pptx
Session-1 edited.pptx
 
Compose camp 2.pptx
Compose camp 2.pptxCompose camp 2.pptx
Compose camp 2.pptx
 
GDSC_day_1.pptx
GDSC_day_1.pptxGDSC_day_1.pptx
GDSC_day_1.pptx
 
Wrapper class
Wrapper classWrapper class
Wrapper class
 
Day3New GDSC.pptx
Day3New GDSC.pptxDay3New GDSC.pptx
Day3New GDSC.pptx
 
Android Development | Compose camp day 3 | GDSC SEC Sasaram.pdf
Android Development | Compose camp day 3 | GDSC SEC Sasaram.pdfAndroid Development | Compose camp day 3 | GDSC SEC Sasaram.pdf
Android Development | Compose camp day 3 | GDSC SEC Sasaram.pdf
 

Recently uploaded

POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting DataJhengPantaleon
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991RKavithamani
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 

Recently uploaded (20)

POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 

Compose Camp - Unit 1 (1).pptx

  • 1. This work is licensed under the Apache 2.0 License Compose Camp Android Basics with Compose: Unit 1 Nishant Khandhar
  • 2. Compose Camp is a hands-on introduction to learning how you can build Android apps with Jetpack Compose. This work is licensed under the Apache 2.0 License What is Compose Camp?
  • 3. ● Basic computer literacy ● Basic math skills ● Computer & headphones ● Internet connection ● Android Studio This work is licensed under the Apache 2.0 License Prerequisites
  • 4. ● Build your first Android apps ● Set up Android Studio on your computer ● Learn the basics of the Kotlin programming language ● Learn Jetpack Compose ● Discover resources to continue learning This work is licensed under the Apache 2.0 License Compose Camp Learning Objectives
  • 5. This work is licensed under the Apache 2.0 License INDEX 1. Introduction to Kotlin Playground. 2. Variables and Data types. 3. Functions in Kotlin. 4. Quiz
  • 6. Kotlin Playground This work is licensed under the Apache 2.0 License Write and run Kotlin code in the browser.
  • 7. In computer programming, there's the concept of a variable, which is a container for a single piece of data. You can envision it as a box that contains a value. The box has a label, which is the name of the variable. By referring to the box by its name, you have access to the value it holds. This work is licensed under the Apache 2.0 License Variables
  • 8. years old Variable s name age My name is $name,and I am $age This work is licensed under the Apache 2.0 License “ALEX” 20
  • 9. Variable s Name value: Meghan Age value: 28 Output: My name is Meghan and I am 28 years old Name value: Janet Age value: 49 Output: My name is Janet and I am 49 years old name age My name is and I am years old This work is licensed under the Apache 2.0 License
  • 10. Basic data types This work is licensed under the Apache 2.0 License Kotlin Data type What kind of data it can contain Example literal values String Text “Add contact” “Search” Int Whole integer number 32 -59873 Double Decimal number 2.0 -37123.9999 Float Decimal number (less precise than a Double). Has an f or F at the end of the number. 5.0f -1630.209f Boolean true or false. Use this data type when there are only two possible values. true false
  • 11. val keyword This work is licensed under the Apache 2.0 License Use when you expect the variable value will not change. Example: name var keyword Use when you expect the variable value can change. Example: age Defining a variable Use the assignment operator (=) to assign a value to a variable either during declaration of the variable or updating the variable.
  • 12. Defining a variable Variables start with a var or val keyword. fun main() { val name: String = "Meghan" var age: Int = 28 } This work is licensed under the Apache 2.0 License
  • 13. Defining a variable All variables must have a name. fun main() { val name: String = "Meghan" var age: Int = 28 } This work is licensed under the Apache 2.0 License
  • 14. Defining a variable Data type is the type of data that the variable holds. fun main() { val name: String = "Meghan" var age: Int = 28 } This work is licensed under the Apache 2.0 License
  • 15. Defining a variable The initial value is the value that is stored in the variable. fun main() { val name: String = "Meghan" var age: Int = 28 } This work is licensed under the Apache 2.0 License
  • 16. Functions A function is a segment of a program that performs a specific task. You can have many functions in your program or only a single one. The main() function doesn’t actually get called anywhere in your code; the Kotlin compiler uses it as a starting point.
  • 17. Defining a function Functions begin with the fun keyword followed by function name and parentheses and curly braces. fun namer () { } This work is licensed under the Apache 2.0 License fun main() { println(“Hello World”) } fun helloWorld () { }
  • 18. Defining a function Functions have a name so that they can be called. fun displayIntroduction() { } This work is licensed under the Apache 2.0 License
  • 19. fun helloWorld () { println(“Happy Birthday, Alex”) println(“You are now 20 years old”) } Defining a function Functions need a set of parentheses after the function name in order to surround the function inputs. This work is licensed under the Apache 2.0 License
  • 20. Defining a function The curly braces make up the function body and contain the instructions needed to execute a task. fun displayIntroduction() { } This work is licensed under the Apache 2.0 License
  • 21. Putting it together fun displayIntroduction() { // We will fill this out! } This work is licensed under the Apache 2.0 License Output: Hi I’m Meghan and I am 28 years old
  • 22. Putting it together This work is licensed under the Apache 2.0 License fun displayIntroduction() { val name : String = "Meghan" val age : Int = 28 println("Hi I'm $name and I am $age years old") }
  • 23. Putting it together This work is licensed under the Apache 2.0 License fun main() { displayIntroduction() } fun displayIntroduction() { val name : String = "Meghan" val age : Int = 28 println("Hi I'm $name and I am $age years old") } Output: Hi I’m Meghan and I am 28 years old
  • 24. Returning in a function We can return an output from a function as per its defined output datatype. fun displayIntroduction() : String { return “HelloWorld”; } This work is licensed under the Apache 2.0 License
  • 25. Parameters of a function We can pass extra information into a function via parameters which are declared between the parentheses. fun add(n1 : Int, n2 : Int) { return n1 + n2 } This work is licensed under the Apache 2.0 License
  • 26. Parameters of a function These parameters can also have default values. fun add(n1 : Int = 0, n2 : Int = 0) { return n1 + n2 } This work is licensed under the Apache 2.0 License
  • 27. Arguments of a function While calling a function in another function, the values we pass to the parameters defined are known as Arguments. fun main() { var a : Int = 2 var b : Int = 3 println(add(a, b)) } This work is licensed under the Apache 2.0 License
  • 28. Work on Unit 1, Pathway 1 This work is licensed under the Apache 2.0 License Have a Question? Just ask