⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 coursedesign.java

📁 JAVA实现: 将输入的中文字符转换成拼音
💻 JAVA
字号:
import java.io.*;
import java.util.LinkedHashMap;
import java.util.Scanner;

public class CourseDesign {
	private static LinkedHashMap spellMap = null;

	static {
		if (spellMap == null) {
			spellMap = new LinkedHashMap(400);
		}
		try {
			initialize();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}


	private static void readfile(File f) throws IOException {

		//BufferedReader read = new BufferedReader(new FileReader(f));
		Scanner in = new Scanner(f);
		String key = "";
		String value = "";	
		while (in.hasNextLine()) {
			String str = in.nextLine();
			key = str.substring(0, 4);
			for (int i = 6; i < str.length(); ++i) {
				if (str.charAt(i) >= '0' && str.charAt(i) <= '9'
						|| str.charAt(i) == ')' || str.charAt(i) == ',') {
					break;
				} else
					value += String.valueOf(str.charAt(i));
			}
			spellMap.put(key, value);
			key = "";
			value = "";
		}
		in.close();
	}


	public static void toPinYin(String str1) {
		String str[] = new String[str1.length()];
		for (int i = 0; i < str1.length(); ++i) {
			str[i] = Integer.toHexString((int) (str1.charAt(i))).toUpperCase();
		}
		String value = "";
		String value1 = "";
		String value2 = "";
		for (int i = 0; i < str.length; ++i)
		{
			value2 =(String) spellMap.get(str[i]);
			if(value2!=null){
			value += value2;
			value1 +=  String.valueOf(value2.charAt(0));}
			else
			{
				value += String.valueOf(str1.charAt(i));
				value1 +=  String.valueOf(str1.charAt(i));
			}
		}
		
		System.out.println("全拼音: " +value.toUpperCase());
		System.out.println("推荐字段名:   "+value1.toUpperCase());
	}

	private static void initialize() throws IOException {
		File f = new File("字典.txt");
		readfile(f);
		//Properties props = new Properties("zidian.properties");
	}

}

⌨️ 快捷键说明

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