Skip to content

Tuwaiq-jed-kot1/HW-Week1_Day04_nullSafety_String_number-

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

1 Commit
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

HW_Week1_Day4_StringsAndNumbers πŸ˜ƒ


The HomeWork has three components:

  • Null safety.

  • Strings.

  • Numbers.

    Note: You must save your solution as solution.kt to be submitted before 9AM.

Instructions πŸ“‹

Part I - Null Safety.


In the code below, add an if statement to the beginning of getLength that returns zero if str is null:

fun getLength(str: String?) : Int {
    // Add null check here
    
    return str.length;
}

fun main(args: Array<String>) {
  println(getLength('This is a string!'))
}

Part II - Strings.


Write a Kotlin program to get a substring of a given string between two specified positions.

Sample Output:

old = The quick brown fox jumps over the lazy dog.
new = brown fox jumps.

Part III - Numbers.


Write a Kotlin program to convert temperature from Fahrenheit to Celsius degree.

Input a degree in Fahrenheit: 212 Or Null

Use this equation:

C = (5 (F-32)) / 9.

Expected Output:

212.0 degree Fahrenheit is equal to 100.0 in Celsius.

Learning Resources πŸ“š

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages