Skip to content

Instantly share code, notes, and snippets.

@camark
Created February 10, 2017 08:44
Show Gist options
  • Select an option

  • Save camark/911bf57f3226e9d1cb010567ca08624c to your computer and use it in GitHub Desktop.

Select an option

Save camark/911bf57f3226e9d1cb010567ca08624c to your computer and use it in GitHub Desktop.
Add 0 to number output
package com.gm;
import java.io.PrintStream;
import java.lang.reflect.Field;
public class Ttx {
public static void main(String[] args) throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
// TODO Auto-generated method stub
int a=20;
int b=10;
//me(a,b);
me1(a,b);
System.out.println("a="+a);
System.out.println("b="+b);
}
private static void me1(int a, int b) {
// TODO Auto-generated method stub
System.setOut(new PrintStream(System.out){
@Override
public void println(String s){
super.println(s+"0");
}
});
}
private static void me(Integer a, Integer b) throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
// TODO Auto-generated method stub
Integer aa=a;
Integer bb=b;
Class<? extends Integer> class1=aa.getClass();
Field afField=class1.getDeclaredField("value");
afField.setAccessible(true);
afField.setInt(aa, 100);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment