创建自己的工具库可以减少或消除重复程序代码,减少输入负担。创建后,用 import static 语句导入。
Print.javapackage com.hlb.util;import java.io.PrintStream;public class Print { public static void print(){ System.out.println(); } public static void print(Object ob){ System.out.println(ob); } public static void printb(Object ob){ System.out.print(ob); } public static PrintStream printf(String format,Object...args){ return System.out.printf(format,args); } }PrintTry.javapackage com.hlb.main;import static com.hlb.util.Print.*; //导入自定义工具类public class PrintTry { /** * @param args */ public static void main(String[] args) { print(100+"123 "); printb("she"); printf("45"+34+343); }}