I have a String with digits at index 4 and 18. I need to print the String to the Java console such that the number increments by one until it reaches the number 40.
String:
String a = "AAA_0_BBB_CCC(DDD_0_EEE)" ;
Desired Output in Console:
AAA_1_BBB_CCC(DDD_1_EEE)
AAA_2_BBB_CCC(DDD_2_EEE)
AAA_3_BBB_CCC(DDD_3_EEE)
.
.
.
AAA_40_BBB_CCC(DDD_40_EEE)
My program (see below) prints digits from 0 to 9. But I didn't know how to continue the loop with double digits (11 to 40). I can rewrite the program for each index(4,5,19,20) but i was wondering if there was a simpler way to handle it.
My program for changing at index 4 and 18 with one digit:
public static void main(String[] args){
StringBuffer buf = new StringBuffer( a );
String a = "AAA_0_BBB_CCC(DDD_0_EEE)" ;
for (int i = 0; i< 10; i++){
//make i a character j
String k = Integer.toString(i);
char j = k.charAt(0);
//replace index position 4 and 18
buf.setCharAt( 4, j );
buf.setCharAt( 18, j );
String z = buf.toString( );
System.out.println(z);
}