splitmanywords.java

来自「一个简单的java程序」· Java 代码 · 共 48 行

JAVA
48
字号
/*
  Written by: qa
  First written: 15/09/06
  Last modified: 15/09/06
*/

import sheffield.*;

public class SplitManyWords {
    public static void main(String[] args) {

	// open a file
	EasyReader file = new EasyReader("manywords.txt");

	// process line by line
	while (!file.eof()) {

	    // read a string
	    String s = file.readString();

	    // remove leading/trailing white spaces & place a space in the end
	    s = s.trim() + ' ';

	    // find the length of the string
	    int l = s.length();

	    // repeat until all spaces are processed
	    while (l>0) {

		// find the position of the first space
		int i = s.indexOf(' ');

		// identify the leading word and the rest of the string
		String w = s.substring(0, i);
		s = s.substring(i+1, l);

		// display words
		if (w.length()>0) {
		    System.out.println(w);
		}

		// find the length of the string
		l = s.length();
	    }
	}
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?