工具类的编写
Main函数类
public class myMain { public static void main(String[] args) { int [] arr = {10,20,1,5}; Tool.showArr(arr); } }
工具类public class Tool {
//无参构造私有化 private Tool(){}; //打印数组内的元素方法
//方法静态修饰才能被调用
public static void showArr(int [] intArr) { for (int i = 0; i < intArr.length; i++) { System.out.print(intArr[i]+" "); } }
//打印函数的重构 public static void showArr(String [] strArr) { for (int i = 0; i < strArr.length; i++) { System.out.print(strArr[i]+" "); } }
//打印函数的重构
public static void showArr(char [] charArr)
{
for (int i = 0; i < charArr.length; i++)
{
System.out.print(charArr[i]+" ");
}
}
}

浙公网安备 33010602011771号