I tried in many times but don't know how to change str.substring(0,i) into str.charAt(i)
Please help
I tried to make a result as below but I struggle from str.substinrg(0,i) to str.charAt(i)
If i would like to make a result as below, at this point, how should i have to change it?
repeatFront("Chocolate", 4) → "ChocChoChC"
repeatFront("Chocolate", 3) → "ChoChC"
repeatFront("Ice Cream", 2) → "IcI"
below code is not successfully correct
public String repeatFront(String str, int n) {
int i;
String newStr;
for(i = 0; i < str.length(); i++)
{
newStr = Character.toString(str.charAt(n));
}
return str;
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…