一道打印的面试题
题目如下:
public static void main(String[] args) { int a=10; int b=10; method(a, b); System.out.println("a***"+a); System.out.println("b***"+b); }
如何打印出
a***1000
b***1000
方法一:
public static void method(int a,int b) { a = a*100; b = b*100; System.out.println("a***"+a); System.out.println("b***"+b); System.exit(0);//退出虚拟机 }
方法二:
public static void method(int a, int b) {
        PrintStream Sys = new PrintStream(System.out){
            @Override
            public void println(String x) {
                super.println("a="+a*100+", b="+b*100);
            }
        };
        System.setOut(Sys);
//        try {
//            System.setOut(new PrintStream(new FileOutputStream("D:\\a.txt")));
//        } catch (FileNotFoundException e) {
//            e.printStackTrace();
//        }
    }
    程序员的眼里,不止有代码和bug,还有诗与远方和妹子!!!
                    
                
                
            
        
浙公网安备 33010602011771号