题目如下:

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();
// }
}

相关文章:

  • 2021-12-23
  • 2021-12-17
  • 2021-07-04
  • 2022-12-23
猜你喜欢
  • 2021-06-05
  • 2021-05-17
  • 2022-12-23
  • 2021-11-24
相关资源
相似解决方案