2018年2月20日 星期二

[JAVA] 於不同package間導入數值

※ 此程式碼並非優化版本,僅供個人學習用途,若有任何問題請告知。


程式碼如下:
package main;
import test.test;
public class abc {
public static void pint(int n) { //print something integer
System.out.print(n+" ");
}
public static void pdouble(double n) {//print something double
System.out.print(n+" ");
}
public static void pstr(String str) { //print something
System.out.println(str);
}
public static void sint(int i, int j) { //swap something integer
test.i = j;
test.j = i;
}
public static void sdouble(double i, double j) { //swap something double
double temp = i;
i = j;
j = temp;
}
}
view raw abc.java hosted with ❤ by GitHub
package test;
import main.*;
public class test {
public static int i = 10, j = 20;
public static void main(String args[]){
String str1 = "abc";
abc.pstr(str1);
abc.sint(i,j);
abc.pint(i);
abc.pint(j);
}
}
view raw test.java hosted with ❤ by GitHub
結果如下:
abc
20 10


沒有留言:

張貼留言