📄 spaces.java
字号:
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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -