题目如下:
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();
// }
}