Not getting output

problem occuring at line 18 of code; sb.insert(i, d)

code: import java.util.;
import java.io.
;
public class Main {

public static void main(String args[]) throws IOException {

   Scanner sc = new Scanner(System.in);
   String s = sc.nextLine();

    asciiDifference(s);
}

public static void asciiDifference(String s) {
    StringBuilder sb = new StringBuilder(s);
    int d = 0;
    for(int i = 1; i < sb.length(); i++) {
        d = sb.charAt(i) - sb.charAt(i-1);
        sb.insert(i, d);
        i++;
    }
    System.out.println(sb);
}

}

Use coding blocks ide to write code and share the link here.

In line number 18 you are getting error because the for loop is becoming an infinite loop in some cases because of 2 reasons :

  1. as you are inserting the difference of 2 characters in the string as the size of string is also increasing and in loop you have condition i < size.length() is never achieved.
  2. when you insert a number in the string at a position , next time the loop is executed the number is also taken for difference.

For more clarity you can insert a print statement after sb.insert() and debug your code.