fork download
  1. import java.util.function.*;
  2.  
  3. class Ideone {
  4. public static void main(String[] args) throws java.lang.Exception {
  5. Function<Integer, String> f = number -> {
  6. String result = "";
  7. for (int quantity = 2, i; number > 2; quantity *= 2) {
  8. number = number / 4 * 2; // Make sure that the next is half or half - 1 if odd
  9. for (i = quantity; i > 0; i--) { // copy "quantity" times.
  10. result += number;
  11. }
  12. result += "\n"; // append new line
  13. }
  14. return result;
  15. };
  16. System.out.println(f.apply(50));
  17. }
  18. }
Success #stdin #stdout 0.08s 711168KB
stdin
Standard input is empty
stdout
2424
12121212
66666666
2222222222222222