我們如何在 Java 方法中按值傳遞引數?
按值傳遞引數是指用一個引數呼叫方法。透過這種方式,引數值傳遞給引數。
示例
public class SwappingExample {
public static void swapFunction(int a, int b) {
int c = a+b;
System.out.println("Sum of the given numbers is ::"+c);
}
public static void main(String[] args) {
int a = 30;
int b = 45;
swapFunction(a, b);
}
}
輸出
Sum of the given numbers is ::75
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP