日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

kotlin 两个数字相加_Kotlin程序交换两个数字

發布時間:2025/3/11 编程问答 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 kotlin 两个数字相加_Kotlin程序交换两个数字 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

kotlin 兩個數字相加

Given two numbers, we have to swap them.

給定兩個數字,我們必須交換它們。

Example:

例:

Input:First number: 10Second number: 20Output:First number: 20Second number: 10

To 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程序交换两个数字的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。