fork download
  1. class Ideone {
  2. public static void main(String[] args) {
  3. final int valueForJ = 37;
  4. System.out.println(replaceJWith("5+2+5+2 --j *2*7+3", valueForJ));
  5. System.out.println(replaceJWith("5+2+5+2 j-- *2*7+3", valueForJ));
  6. System.out.println(replaceJWith("5+2+5+2 ++j *2*7+3", valueForJ));
  7. System.out.println(replaceJWith("5+2+5+2 j++ *2*7+3", valueForJ));
  8. }
  9.  
  10. public static String replaceJWith(String s, int valueForJ) {
  11. s = s.replaceAll("j(?:[+]{2}|[-]{2})", Integer.toString(valueForJ));
  12. s = s.replaceAll("[+]{2}j", Integer.toString(valueForJ + 1));
  13. return s.replaceAll("[-]{2}j", Integer.toString(valueForJ - 1));
  14. }
  15. }
Success #stdin #stdout 0.07s 33524KB
stdin
Standard input is empty
stdout
5+2+5+2 36 *2*7+3
5+2+5+2 37 *2*7+3
5+2+5+2 38 *2*7+3
5+2+5+2 37 *2*7+3