工具类的编写

 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]
+" ");
      }
   }
}

 

 

posted @ 2023-06-28 16:39  筱白君  阅读(32)  评论(0)    收藏  举报