Skip to main content
added 96 characters in body
Source Link
resueman
  • 442
  • 2
  • 7

Java

public class print {
    public static char getNum() throws Exception{
        String method = print.class.getSimpleName()+Splitter.class.getDeclaredMethods().length;
        try{
            return (char)Splitter.class.getMethod(method).invoke(null);
        }catch(Exception e){return ' ';}
    }
}
class Splitter{
    public static char print1(){
        return PrinterP.printgetNum();
    }
 
}
class PrinterP{
    public static char printgetNum(){
        String s = Thread.currentThread().getStackTrace()[2][P.class.getDeclaredMethods().length].getMethodName();
        return s.charAt(s.length()-1P.class.getSimpleName().length());
    }
    public void doNothing(){}
}

Can be adjusted to return any other positive number n by adding the methods printX for X from 1 to n into Splitter. For example, modifying Splitter to

class Splitter{
    public static char print1(){
        return P.getNum();
    }
    public static char print2(){
        return P.getNum();
    }
}

Will return '2', without any other changes necessary. The added methods should, apart from the name, be an exact duplicate of print1. Uses Uses reflection to get the number of methods in splitter, and call a function with that name. Printer.printP.getNum, which is then called, reads the stack trace and parses out the last character in the calling method, and displays it.

Calling print.getNum() return the character '1'

Edit - modified to use no String/integer/etc literals.

Java

public class print {
    public static char getNum(){
        String method = print.class.getSimpleName()+Splitter.class.getDeclaredMethods().length;
        try{
            return (char)Splitter.class.getMethod(method).invoke(null);
        }catch(Exception e){return ' ';}
    }
}
class Splitter{
    public static char print1(){
        return Printer.print();
    }
 
}
class Printer{
    public static char print(){
        String s = Thread.currentThread().getStackTrace()[2].getMethodName();
        return s.charAt(s.length()-1);
    }
}

Can be adjusted to return any other positive number n by adding the methods printX for X from 1 to n into Splitter. The added methods should, apart from the name, be an exact duplicate of print1. Uses reflection to get the number of methods in splitter, and call a function with that name. Printer.print, which is then called, reads the stack trace and parses out the last character in the calling method, and displays it.

Edit - modified to use no String literals.

Java

public class print {
    public static char getNum() throws Exception{
        String method = print.class.getSimpleName()+Splitter.class.getDeclaredMethods().length;
        return (char)Splitter.class.getMethod(method).invoke(null);
    }
}
class Splitter{
    public static char print1(){
        return P.getNum();
    }
}
class P{
    public static char getNum(){
        String s = Thread.currentThread().getStackTrace()[P.class.getDeclaredMethods().length].getMethodName();
        return s.charAt(s.length()-P.class.getSimpleName().length());
    }
    public void doNothing(){}
}

Can be adjusted to return any other positive number n by adding the methods printX for X from 1 to n into Splitter. For example, modifying Splitter to

class Splitter{
    public static char print1(){
        return P.getNum();
    }
    public static char print2(){
        return P.getNum();
    }
}

Will return '2', without any other changes necessary. The added methods should, apart from the name, be an exact duplicate of print1. Uses reflection to get the number of methods in splitter, and call a function with that name. P.getNum, which is then called, reads the stack trace and parses out the last character in the calling method, and displays it.

Calling print.getNum() return the character '1'

Edit - modified to use no String/integer/etc literals.

added 14 characters in body
Source Link
resueman
  • 442
  • 2
  • 7

Java

public class print {
    public static voidchar maingetNum(String[] args){
        String method = print.class.getSimpleName()+Splitter.class.getDeclaredMethods().length;
        try{
            return (char)Splitter.class.getMethod(method).invoke(null);
        }catch(Exception e){return ' ';}
    }
}
class Splitter{
    public static voidchar print1(){
        return Printer.print();
    } 

}
class Printer{
    public static voidchar print(){
        String s = Thread.currentThread().getStackTrace()[2].getMethodName();
        System.out.println(return s.charAt(s.length()-1));
    }
}

Can be adjusted to printreturn any other positive number n by adding the methods printX for X from 1 to n into Splitter. The added methods should, apart from the name, be an exact duplicate of print1. Uses reflection to get the number of methods in splitter, and call a function with that name. Printer.print, which is then called, reads the stack trace and parses out the last character in the calling method, and displays it.

Edit - modified to use no String literals.

Java

public class print {
    public static void main(String[] args){
        String method = print.class.getSimpleName()+Splitter.class.getDeclaredMethods().length;
        try{
            Splitter.class.getMethod(method).invoke(null);
        }catch(Exception e){}
    }
}
class Splitter{
    public static void print1(){
        Printer.print();
    }
}
class Printer{
    public static void print(){
        String s = Thread.currentThread().getStackTrace()[2].getMethodName();
        System.out.println(s.charAt(s.length()-1));
    }
}

Can be adjusted to print any other positive number n by adding the methods printX for X from 1 to n into Splitter. The added methods should, apart from the name, be an exact duplicate of print1. Uses reflection to get the number of methods in splitter, and call a function with that name. Printer.print, which is then called, reads the stack trace and parses out the last character in the calling method, and displays it.

Edit - modified to use no String literals.

Java

public class print {
    public static char getNum(){
        String method = print.class.getSimpleName()+Splitter.class.getDeclaredMethods().length;
        try{
            return (char)Splitter.class.getMethod(method).invoke(null);
        }catch(Exception e){return ' ';}
    }
}
class Splitter{
    public static char print1(){
        return Printer.print();
    } 

}
class Printer{
    public static char print(){
        String s = Thread.currentThread().getStackTrace()[2].getMethodName();
        return s.charAt(s.length()-1);
    }
}

Can be adjusted to return any other positive number n by adding the methods printX for X from 1 to n into Splitter. The added methods should, apart from the name, be an exact duplicate of print1. Uses reflection to get the number of methods in splitter, and call a function with that name. Printer.print, which is then called, reads the stack trace and parses out the last character in the calling method, and displays it.

Edit - modified to use no String literals.

Source Link
resueman
  • 442
  • 2
  • 7

Java

public class print {
    public static void main(String[] args){
        String method = print.class.getSimpleName()+Splitter.class.getDeclaredMethods().length;
        try{
            Splitter.class.getMethod(method).invoke(null);
        }catch(Exception e){}
    }
}
class Splitter{
    public static void print1(){
        Printer.print();
    }
}
class Printer{
    public static void print(){
        String s = Thread.currentThread().getStackTrace()[2].getMethodName();
        System.out.println(s.charAt(s.length()-1));
    }
}

Can be adjusted to print any other positive number n by adding the methods printX for X from 1 to n into Splitter. The added methods should, apart from the name, be an exact duplicate of print1. Uses reflection to get the number of methods in splitter, and call a function with that name. Printer.print, which is then called, reads the stack trace and parses out the last character in the calling method, and displays it.

Edit - modified to use no String literals.