0
Scanner kb = new Scanner(System.in);
System.out.print(">> ");
String line = kb.nextLine();
line = line.trim();
int i = 0;
do {
int j = i;
while ((!line.substring(j, j + 1).equals(" ")) && (j < line.length())) {
//while ((j < line.length())&&(!line.substring(j, j + 1).equals(" "))) {
j++;
}
System.out.println("-> " + line.substring(i, j));
i = j;
while ((line.substring(i, i + 1).equals(" "))&&(i<line.length())) {
//while ((i < line.length()) && (line.substring(i, i + 1).equals(" "))) {
i++;
}
}while (i < line.length());
爲什麼表達....普通表達
while ((!line.substring(j, j + 1).equals(" ")) && (j < line.length()))
不等於與
while ((j < line.length())&&(!line.substring(j, j + 1).equals(" ")))
因爲在使用邏輯與時,如果AND運算中的第一個操作數計算結果爲false,那麼下一個操作數將不會被計算。 – bhups 2011-03-09 05:40:22