(String[] args)
| 23 | } |
| 24 | } |
| 25 | public static void main(String[] args) { |
| 26 | |
| 27 | test("Add brackets", |
| 28 | s -> Optional.of("[" + s + "]")); |
| 29 | |
| 30 | test("Increment", s -> { |
| 31 | try { |
| 32 | return Optional.of( |
| 33 | Integer.parseInt(s) + 1 + ""); |
| 34 | } catch(NumberFormatException e) { |
| 35 | return Optional.of(s); |
| 36 | } |
| 37 | }); |
| 38 | |
| 39 | test("Replace", |
| 40 | s -> Optional.of(s.replace("2", "9"))); |
| 41 | |
| 42 | test("Take last digit", |
| 43 | s -> Optional.of(s.length() > 0 ? |
| 44 | s.charAt(s.length() - 1) + "" |
| 45 | : s)); |
| 46 | } |
| 47 | } |
| 48 | /* Output: |
| 49 | ---( Add brackets )--- |