问题遇到的现象和发生背景
对一个文本中句子里的单词进行操作
用代码块功能插入代码,请勿粘贴截图
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
public class lab4 {
public static boolean isCharVowel(char ch) {
return ch == 'a' || ch == 'e' || ch == 'u'
|| ch == 'i' || ch == 'o' || ch == 'y';
}
public static void main(String[] args) {
String path = "F:\\lab.txt";
File file = new File(path);
FileReader fr = null;
try {
fr = new FileReader(file);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
BufferedReader br = new BufferedReader(fr);
String line;
try {
while((line = br.readLine()) != null){
for (String str : line.split(" ")) {
char c = str.charAt(0);
String toPrint = str;
if (isCharVowel(c)) {
toPrint = String.valueOf(c).toUpperCase() +
str.substring(1);
}
System.out.print(toPrint + " ");
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
我想要达到的结果
将文本中每一句中的单词逆序排列(1.句子顺序不能改变 2.每个单词里字母的顺序不能改变)