当前位置:编程学习 > JAVA >>

Java 源代码 计算出拼音的声调字母是哪个

import java.io.*;//导入操作要用到的类
 
 
public class main {
public static void main(String args[]) {
File file = new File("c:/test.txt");// 源文件位置
FileReader fr;
try {
fr = new FileReader(file);
BufferedReader in = new BufferedReader(fr);// 包装文件输入流,可整行读取
String line;  www.zzzyk.com
try {
while ((line = in.readLine()) != null) {
String a = pinyin(line);
int shengdiaoLetter = Integer.parseInt(a.substring(
a.length() - 1, a.length()));
a = a.substring(0, a.length() - 1) + " "
+ a.substring(shengdiaoLetter, shengdiaoLetter + 1);
System.out.println(a);
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}// 创建文件输入流
}
 
 
private static String pinyin(String input) {
int position = 0;
int onlyaeiou = 0;
input = input.toLowerCase();
// 单个韵母不必说。 (单个的韵母,当然就标它上面了)
if (input.contains("a")) {
onlyaeiou++;
}
if (input.contains("e")) {
onlyaeiou++;
}
if (input.contains("i")) {
onlyaeiou++;
}
if (input.contains("o")) {
onlyaeiou++;
}
if (input.contains("u")) {
onlyaeiou++;
}
if (input.contains("v")) {
onlyaeiou++;
}
if (onlyaeiou == 1) {
if (input.contains("a")) {
position = input.indexOf("a");
}
if (input.contains("e")) {
position = input.indexOf("e");
}
if (input.contains("i")) {
position = input.indexOf("i");
}
if (input.contains("o")) {
position = input.indexOf("o");
}
if (input.contains("u")) {
position = input.indexOf("u");
}
if (input.contains("v")) {
position = input.indexOf("v");
}
return input + position;
}
 
 
if (input.contains("a")) {
position = input.indexOf("a");
return input + position;
}
// 没有a母找o e ,
else if (input.contains("o")) {
position = input.indexOf("o");
return input + position;
} else if (input.contains("e")) {
position = input.indexOf("e");
return input + position;
}
// iu 并列标在后,
if (input.contains("iu")) {
position = input.indexOf("iu") + 1;
return input + position;
}
if (input.contains("a")) {
position = input.indexOf("a");
return input + position;
}
if (input.contains("e")) {
position = input.indexOf("e");
return input + position;
}
if (input.contains("i")) {
position = input.indexOf("i");
return input + position;
}
if (input.contains("o")) {
position = input.indexOf("o");
return input + position;
}
if (input.contains("u")) {
position = input.indexOf("u");
return input + position;
}
if (input.contains("v")) {
position = input.indexOf("v");
return input + position;
}
return input;
}
}
补充:软件开发 , Java ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,