它讓我噁心..你能幫我這個嗎?我的問題是確定我的Java程序上的空格和它的索引,但我不知道如何識別索引(JAVA)。繼承人我的代碼:確定指數(爪哇)
import java.util.*;
public class CountSpaces
{
public static void main (String[] args)
{
System.out.print ("Enter a sentence or phrase: ");
Scanner input=new Scanner(System.in);
String str=input.nextLine();
int count = 0;
int limit = str.length();
for(int i = 0; i < limit; ++i)
{
if(Character.isWhitespace(str.charAt(i)))
{
++count;
}
}
感謝提前。
'i'是索引。 –