fork download
  1. class Ideone {
  2. public static void main (String[] args) {
  3. String str = "Gateway";
  4. int i = 1;
  5. int j = 3;
  6. String first = str.substring(0, i);
  7. char second = str.charAt(j);
  8. String third = str.substring(i + 1, j); // Note: corrected bug!
  9. char fourth = str.charAt(i);
  10. String fifth = str.substring(j + 1);
  11.  
  12. System.out.println(first + second + third + fourth + fifth);
  13.  
  14. }
  15. }
Success #stdin #stdout 0.14s 37328KB
stdin
Standard input is empty
stdout
Getaway