Difference inn ASCII code

one test case failed
code
import java.util.;
public class Main {
public static void main(String args[]) {
Scanner s1= new Scanner(System.in);
String s=s1.nextLine();
StringBuilder sb=new StringBuilder(s);
int n=sb.length();
for(int i=0;i<2
n-2;i=i+2) {
int c=sb.charAt(i+1)-sb.charAt(i);
sb.insert(i+1,c);
}
System.out.print(sb);

}

}

your logic is fine but there is a little mistake…you are assuming that your integer will be of 1 character only(for ex 1,2,3,4,5)…but difference can be negative(for ex -1,-2…these characters are of more than one digit) and integer could also be more than one digit(for ex 10,11,12…these characters are more than one digit)…in this question as you will have alphabets only so diff will never be 3 digit…
i have made few changes you can refer this code:
https://ide.codingblocks.com/s/72117

1 Like

Hi @priyanshirajpal
As you are not responding to this thread, I am marking your doubt as Resolved for now. Re-open it if required.

Please mark your doubts as resolved in your course’s “ Ask Doubt ” section, when your doubt is resolved.