kotlin 两个数字相加_Kotlin程序交换两个数字
kotlin 兩個數字相加
Given two numbers, we have to swap them.
給定兩個數字,我們必須交換它們。
Example:
例:
Input:First number: 10Second number: 20Output:First number: 20Second number: 10To swap two numbers – here we are using third variable/temporary variable (consider – first contains the first number, second contains the second number and temp is a temporary variable).
要交換兩個數字 –在這里,我們使用第三個變量/臨時變量(考慮– 第一個包含第一個數字, 第二個包含第二個數字,而temp是一個臨時變量)。
Assign the first number (first) to the temporary variable (temp)
將第一個數字( first )分配給臨時變量( temp )
Now, assign the second number (second) to the variable first.
現在,將第二個數字( second )分配給變量first 。
Now, assign the temp (that contains the first number) to the second.
現在,將溫度 (包含第一個數字)分配給第二個 。
Finally, values are swapped, print them on the screen.
最后,交換值,然后將其打印在屏幕上。
計劃在Kotlin交換兩個數字 (Program to swap two numbers in Kotlin)
package com.includehelp.basicimport java.util.*// Main Method Entry Point of Program fun main(arg: Array<String>) {// InputStream to get Inputvar reader = Scanner(System.`in`)// Input two valuesprintln("Enter First Value : ")var first = reader.nextInt();println("Enter Second Value : ")var second = reader.nextInt(); println("Numbers Before Swap : \n first = $first \n second = $second ")//Code for Swap Numbersvar temp = firstfirst=secondsecond=tempprintln("Numbers After Swap : \n first = $first \n second = $second ") }Output
輸出量
Run 1: Enter First Value : 45 Enter Second Value : 12 Numbers Before Swap :first = 45second = 12 Numbers After Swap :first = 12second = 45翻譯自: https://www.includehelp.com/kotlin/swap-two-numbers.aspx
kotlin 兩個數字相加
總結
以上是生活随笔為你收集整理的kotlin 两个数字相加_Kotlin程序交换两个数字的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 如何在Scala中将Double转换为S
- 下一篇: sim800 模式切换_SIM的完整形式