我想写一个简短的程序来代替字符串的计数。所以我想以 0 insted of 1 开始字符串。而且因为它是一个长字符串,我不想自己更改它。所以字符串(在这个例子中)是:字符串 LINE:
- Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore
- magna aliquyam erat,sed diam voluptua。
- 在 vero eos et accusam et justo duo dolores et ea rebum。Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum
- dolor 坐在一起。Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore
- magna aliquyam erat,sed diam voluptua。在 vero eos et accusam et justo duo dolores et ea rebum。Stet clita kasd gubergren,
- no sea takimata sanctus est Lorem ipsum dolor sit amet。
我希望字符串从 0 开始计数。
public static void main(String[] args) {
int Counter = 1;
while (Counter <=300){
int counter2 =1;
String Counterstring ;
Counterstring = (new Integer(counter2)).toString() + ".";
int ReplaceCounting = 0;
String Replace = (new Integer(ReplaceCounting)).toString() + ".";
Line.replace(Counterstring , Replace);
Counter++;
}
System.out.println(Line);
}
}
有人可以告诉我我做错了什么吗?输出是一样的。
编辑:
我把它改成: 我把它改成:
public static void main(String[] args) {
for (int counter = 1; counter <= 300; counter++) {
int NormCounter =1;
int ReplaceCounter = 0;
String NormCounterS = (new Integer(NormCounter)).toString() + ".";
String ReplaceCounterS = (new Integer(ReplaceCounter)).toString() + ".";
Line = Line.replace(NormCounterS , ReplaceCounterS);
++ReplaceCounter;
++NormCounter;
}
System.out.println(Line);
}
}
但它仍然改变了第一个“1”。进入“0。”......所以它的0,2,3,4......但我希望计数去0,1,2,3,4