swap 2 numbers without third variable


Submit solution

Points: 35 (partial)
Time limit: 1.0s
Memory limit: 256M

Authors:
Problem type
Allowed languages
Java 19, Java 8

題目說明

請對調兩數,但不可使用第三個變數與直接依順序輸出達成,陣列也不行(會檢查)

比如A=5,B=4

最後僅輸出System.out.print(A+" "+B);,輸出結果為4 5

輸入限制 正整數

輸入

兩正整數

輸出

對調後的兩整數

請複製以下程式碼後在自己的編譯器上接續作答,作答完後跟以往方式一樣繳交:

Scanner in = new Scanner(System.in);
int a = in.nextInt();
int b = in.nextInt();

//程式碼接續在此

System.out.print(a + " " + b);
in.close();

此題僅一個測資,但請同學繳交後一樣重新整理確認打勾後再離開


Comments

There are no comments at the moment.