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

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

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

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

kotlin 兩個(gè)數(shù)字相加

Given two numbers, we have to swap them.

給定兩個(gè)數(shù)字,我們必須交換它們。

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).

要交換兩個(gè)數(shù)字 –在這里,我們使用第三個(gè)變量/臨時(shí)變量(考慮– 第一個(gè)包含第一個(gè)數(shù)字, 第二個(gè)包含第二個(gè)數(shù)字,而temp是一個(gè)臨時(shí)變量)。

  • Assign the first number (first) to the temporary variable (temp)

    將第一個(gè)數(shù)字( first )分配給臨時(shí)變量( temp )

  • Now, assign the second number (second) to the variable first.

    現(xiàn)在,將第二個(gè)數(shù)字( second )分配給變量first 。

  • Now, assign the temp (that contains the first number) to the second.

    現(xiàn)在,將溫度 (包含第一個(gè)數(shù)字)分配給第二個(gè) 。

  • Finally, values are swapped, print them on the screen.

    最后,交換值,然后將其打印在屏幕上。

計(jì)劃在Kotlin交換兩個(gè)數(shù)字 (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 兩個(gè)數(shù)字相加

總結(jié)

以上是生活随笔為你收集整理的kotlin 两个数字相加_Kotlin程序交换两个数字的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。