Today, a group of Android is discussing a Java face test, as follows:
Class Test{public static void Main (String []args) {int a=10,b=10; Method (A, b); System.out.println ("a=" +a); System.out.println ("b=" +b);}
Implement method, require output, a=100,b=200.
Just see this topic I a, this what write Ah, Java has no pointers or anything.
In a moment a man of God gave the answer:
public static void Method (int a,int b) {System.out.println ("a=100"); System.out.println ("b=200"); System.exit (0);}
Admire, admire, this is to achieve the requirements of the topic. But this should not be the intention of this topic, the real test is the output redirection problem. The correct answers are as follows:
public static void Method (int a,int b) {PrintStream PS = new PrintStream (system.out) {@Overridepublic void println (String x) {if (X.startswith ("a")) Super.println ("a=100"), if (X.startswith ("B")) Super.println ("b=200");}}; System.setout (PS);}
So the point of this topic is the Java output redirection problem, not only the output can be redirected, the input can also be redirected.
Java output redirection