spaces.java
来自「Java经典例程 从外国一大学计算机教授出版物下载的代码 经典」· Java 代码 · 共 42 行
JAVA
42 行
import java.io.*;
import javagently.*;
class Spaces {
/* Removing spaces program by J M Bishop Dec 1997
* ----------------------- Java 1.1
*
* Replaces double spaces by single.
* Illustrates use of string handling methods.
*/
public static void main (String args []) throws IOException {
System.out.println("Program to convert double spaces");
System.out.println("to single ones.");
Stream fin = new Stream (System.in);
String s = "";
int spaceAt, startingFrom;
try {
while (true) {
s = fin.readLine();
if (s==null) throw new EOFException();
startingFrom = 0;
while (true) {
spaceAt = s.indexOf(" ",startingFrom);
if (spaceAt==-1) break;
else if (spaceAt==0)
s = s.substring(1,s.length());
else s = s.substring(0,spaceAt)+" "
+ s.substring(spaceAt+2,s.length());
startingFrom = spaceAt+2;
}
System.out.println(s);
}
}
catch (EOFException e) {}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?