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("[-]{2}j|j[-]{2}", Integer.toString(valueForJ - 1));
  12. return s.replaceAll("[+]{2}j|j[+]{2}", Integer.toString(valueForJ + 1));
  13. }
  14. }
Success #stdin #stdout 0.06s 33048KB
stdin
Standard input is empty
stdout
5+2+5+2 36 *2*7+3
5+2+5+2 36 *2*7+3
5+2+5+2 38 *2*7+3
5+2+5+2 38 *2*7+3