本文目錄一覽:
剛剛開始學習java,麻煩那大家能幫我?怎麼想都沒想明白這個互換。
你好,參考代碼如下:
public class BaiduDemo01 {
private int i ; //第一張牌
private int j ; //第二張牌
public void swap(int i,int j){
this.i = j ;
this.j = i ;
}
public static void main(String[] args) {
BaiduDemo01 bd = new BaiduDemo01() ;
bd.i = 10;
bd.j = 8 ;
System.out.println(“============交換前=============”);
System.out.println(“第一張牌是:” + bd.i) ;
System.out.println(“第二張牌是:” + bd.j) ;
bd.swap(bd.i, bd.j);
System.out.println(“============交換後=============”);
System.out.println(“第一張牌是:” + bd.i) ;
System.out.println(“第二張牌是:” + bd.j) ;
}
}
JAVA類的問題水杯類~~~~在線等,答出的獎勵100分!
第一個問題,一個 Cup 類如下:
public class Cup {
private double volume, weight;
private int color;
public void pour () {}
public void drink () {}
public void setVolume (double volume) {
this.volume = volume;
}
public void setWeight (double weight) {
this.weight = weight;
}
public void setColor (int color) {
this.color = color;
}
public double getVolume () {
return volume;
}
public double getWeight () {
return weight;
}
public int getColor () {
return color;
}
public static void main (String args[]) {
Cup cup = new Cup();
cup.drink();
cup.pour();
}
}
=================================================================
第二個問題:
public class Math {
public double area (double radius) {
return (0.5 * Math.PI * radius * radius);
}
public double area (double width, int height) {
return (width * height);
}
public double sumOf (double arg0, double arg1) {
return (arg0 + arg1);
}
}
java語法問題,不理解為什麼這樣可以交換?
Code; 僅供參考!
輸出結果; 僅供參考!
基本數據類型的變數作為方法的參數傳遞時, 形參變數數值的改變通常不會影響到實參變數的數值, 因為兩個變數都有各自獨立的內存空間, 最終將結果在 oSet 中交換
原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-tw/n/196501.html