Advertisement
k1mby

kotlin

Jun 14th, 2023
4,894
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 3.46 KB | None | 0 0
  1. fun main() {
  2.     val firstNumber = 10
  3.     val secondNumber = 5
  4.     val thirdNumber = 8
  5.    
  6.     val result = add(firstNumber, secondNumber)
  7.     val anotherResult = add(firstNumber, thirdNumber)
  8.    
  9.     println("$firstNumber - $secondNumber = $result")
  10.     println("$firstNumber - $thirdNumber = $anotherResult")
  11. }
  12.  
  13.  
  14. fun add(firstNum: Int, secondNum: Int): Int {
  15.     return firstNum - secondNum
  16. }
  17.  
  18. fun main() {
  19.     val operatingSystem = "ChromeOS"
  20.     val emailId = "[email protected]"
  21.     val mess = displayAlertMessage(operatingSystem, emailId)
  22.     println(mess)
  23. }
  24.  
  25. // Define your displayAlertMessage() below this line.
  26.  
  27. fun displayAlertMessage(os: String, ei: String): String {
  28.     val message = "There's a new sign-in request on $os for your Google Account $ei."
  29.     return message
  30. }
  31.  
  32. fun main() {
  33.     val operatingSystem = "ChromeOS"
  34.     var emailId = "[email protected]"
  35.     val firstUserEmailId = "[email protected]"
  36.     val mess = displayAlertMessage(os= operatingSystem,ei = firstUserEmailId)
  37.     // The following line of code assumes that you named your parameter as emailId.
  38.     // If you named it differently, feel free to update the name.
  39.     println(mess)
  40.  
  41.     val secondUserOperatingSystem = "Windows"
  42.     val secondUserEmailId = "[email protected]"
  43.     val mess2 = displayAlertMessage(secondUserOperatingSystem, secondUserEmailId)
  44.     println(mess2)
  45.  
  46.     val thirdUserOperatingSystem = "Mac OS"
  47.     val thirdUserEmailId = "[email protected]"
  48.     val mess3 = displayAlertMessage(thirdUserOperatingSystem, thirdUserEmailId)
  49.     println(mess3)
  50. }
  51.  
  52.  
  53. fun displayAlertMessage(os: String, ei: String): String {
  54.     val message = "There's a new sign-in request on $os for your Google Account $ei."
  55.     return message
  56. }
  57.  
  58.  
  59. fun main() {
  60.     val Steps = 4000
  61.     val caloriesBurned = pedometerStepsToCalories(Steps);
  62.     println("Walking $Steps steps burns $caloriesBurned calories")
  63. }
  64.  
  65. fun pedometerStepsToCalories(numberOfSteps: Int): Double {
  66.     val caloriesBurnedForEachStep = 0.04
  67.     val totalCaloriesBurned = numberOfSteps * caloriesBurnedForEachStep
  68.     return totalCaloriesBurned
  69. }
  70.  
  71.  
  72. fun main() {
  73.     val timeSpentToday = 200
  74.     val timeSpentYesterday = 220
  75.     val comparison = screenTime(timeSpentToday,timeSpentYesterday)
  76.     println(comparison)
  77. }
  78.  
  79. fun screenTime(timeSpentToday: Int, timeSpentYesterday: Int): Boolean {
  80.     return timeSpentToday > timeSpentYesterday
  81. }
  82.  
  83. fun main() {
  84. //     println("City: Ankara")
  85. //     println("Low temperature: 27, High temperature: 31")
  86. //     println("Chance of rain: 82%")
  87. //     println()
  88.  
  89. //     println("City: Tokyo")
  90. //     println("Low temperature: 32, High temperature: 36")
  91. //     println("Chance of rain: 10%")
  92. //     println()
  93.    
  94. //     println("City: Cape Town")
  95. //     println("Low temperature: 59, High temperature: 64")
  96. //     println("Chance of rain: 2%")
  97. //     println()
  98.    
  99. //     println("City: Guatemala City")
  100. //     println("Low temperature: 50, High temperature: 55")
  101. //     println("Chance of rain: 7%")
  102. //     println()
  103.     val city = "Guatemala City"
  104.     val lowTemp = 50
  105.     val highTemp = 55
  106.     val chance = 7
  107.     val disp = displayWeather(city,lowTemp,highTemp,chance)
  108.     println(disp)
  109. }
  110.  
  111. fun displayWeather(city: String, lowTemp: Int, highTemp: Int, chance: Int): String{
  112.     val c = "City: $city"
  113.     val temp = "Low temperature: $lowTemp, High temperature: $highTemp"
  114.     val ca = "Chance of rain: $chance%"
  115.     return "$c\n$temp\n$ca"
  116. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement