「Java转发英文」转发 英语怎么说

博主:adminadmin 2022-12-03 14:06:05 76

今天给各位分享Java转发英文的知识,其中也会对转发 英语怎么说进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!

本文目录一览:

java代码如何实现中英文转换

使用java提供的国际化功能就可以了。不过建议你使用框架技术中的国际化,框架技术中的国际化都做过封装,实现起来相对简单的多。只需要简单的配置就可以实现中英文或者其他语言的切换了!~

java 数字 转为 英文

public class NumUtil {

public static final String[] enNum = { // 基本数词表

"zero", "one", "tow", "three", "four", "five", "six", "seven", "eight",

"nine", "ten", "eleven", "twelve", "thirteen", "fourteen",

"fifteen", "sixteen", "seventeen", "eighteen", "nineteen",

"twenty", "", "", "", "", "", "", "", "", "", "thirty", "", "", "",

"", "", "", "", "", "", "fourty", "", "", "", "", "", "", "", "",

"", "fifty", "", "", "", "", "", "", "", "", "", "sixty", "", "",

"", "", "", "", "", "", "", "seventy", "", "", "", "", "", "", "",

"", "", "eighty", "", "", "", "", "", "", "", "", "", "ninety" };

public static final String[] enUnit = { "hundred", "thousand", "million",

"billion", "trillion", "quintillion" }; // 单位表

public static void main(String[] args) {

System.out.println(analyze(1)); // 测试数据

System.out.println(analyze(21));

System.out.println(analyze(105));

System.out.println(analyze(3250));

System.out.println(analyze(47826));

System.out.println(analyze(56945781));

}

public static String analyze(long num) { // long型参数,

return analyze(String.valueOf(num)); // 因为long型有极限,所以以字符串参数方法为主

}

public static String analyze(String num) { // 数字字符串参数

// 判断字符串是否为数字

if (!num.matches("\\d+")) {

return String.format("%s is not number", num);

}

num = num.replaceAll("^[0]*([1-9]*)", "$1"); // 把字符串前面的0去掉

if (num.length() == 0) { // 如果长度为0,则原串都是0

return enNum[0];

} else if (num.length() 9) { // 如果大于9,即大于999999999,题目限制条件

return "too big";

}

// 按3位分割分组

int count = (num.length() % 3 == 0) ? num.length() / 3

: num.length() / 3 + 1;

if (count enUnit.length) {

return "too big";

} // 判断组单位是否超过,

// 可以根据需求适当追加enUnit

String[] group = new String[count];

for (int i = num.length(), j = group.length - 1; i 0; i -= 3) {

group[j--] = num.substring(Math.max(i - 3, 0), i);

}

StringBuilder buf = new StringBuilder(); // 结果保存

for (int i = 0; i count; i++) { // 遍历分割的组

int v = Integer.valueOf(group[i]);

if (v = 100) { // 因为按3位分割,所以这里不会有超过999的数

buf.append(enNum[v / 100]).append(" ").append(enUnit[0])

.append(" ");

v = v % 100; // 获取百位,并得到百位以后的数

if (v != 0) {

buf.append("and ");

} // 如果百位后的数不为0,则追加and

}

if (v != 0) { // 前提是v不为0才作解析

if (v 20 || v % 10 == 0) { // 如果小于20或10的整数倍,直接取基本数词表的单词

buf.append(enNum[v]).append(" ");

} else { // 否则取10位数词,再取个位数词

buf.append(enNum[v - v % 10]).append(" ");

buf.append(enNum[v % 10]).append(" ");

}

if (i != count - 1) { // 百位以上的组追加相应的单位

buf.append(enUnit[count - 1 - i]).append(" ");

}

}

}

return buf.toString().trim(); // 返回值

}

}

运行结果:

one

twenty one

one hundred and five

three thousand tow hundred and fifty

fourty seven thousand eight hundred and twenty six

fifty six million nine hundred and fourty five thousand seven hundred and eighty one

JAVA中文符号如何转英文符号

package test;

import java.io.UnsupportedEncodingException;

public class TestString {

public static void main(String args[]) throws UnsupportedEncodingException{

String s = " 强力清除广告,上网更快的浏览器!";

System.out.println(s);

System.out.println(convertMoString(s));

}

public static synchronized String convertMoString(String sMo) {

String sReturn = sMo;

if (sReturn == null) {

return sReturn;

}

try {

sReturn = sReturn.toUpperCase();

sReturn = sReturn.replace(',', ',');

sReturn = sReturn.replace('。', '.');

sReturn = sReturn.replace(';', ';');

sReturn = sReturn.replace('!', '!');

sReturn = sReturn.replace('?', '?');

sReturn = sReturn.replace(':', ':');

sReturn = sReturn.replace('"', '"');

sReturn = sReturn.replace('“', '"');

sReturn = sReturn.replace('”', '"');

// sReturn = sReturn.replace('-', ' ');

// sReturn = sReturn.replace('_', ' ');

sReturn = sReturn.replace(',', ',');

sReturn = sReturn.replace('0', '0');

sReturn = sReturn.replace('1', '1');

sReturn = sReturn.replace('2', '2');

sReturn = sReturn.replace('3', '3');

sReturn = sReturn.replace('4', '4');

sReturn = sReturn.replace('5', '5');

sReturn = sReturn.replace('6', '6');

sReturn = sReturn.replace('7', '7');

sReturn = sReturn.replace('8', '8');

sReturn = sReturn.replace('9', '9');

sReturn = sReturn.replace('A', 'A');

sReturn = sReturn.replace('B', 'B');

sReturn = sReturn.replace('C', 'C');

sReturn = sReturn.replace('D', 'D');

sReturn = sReturn.replace('E', 'E');

sReturn = sReturn.replace('F', 'F');

sReturn = sReturn.replace('G', 'G');

sReturn = sReturn.replace('H', 'H');

sReturn = sReturn.replace('I', 'I');

sReturn = sReturn.replace('J', 'J');

sReturn = sReturn.replace('K', 'K');

sReturn = sReturn.replace('L', 'L');

sReturn = sReturn.replace('M', 'M');

sReturn = sReturn.replace('N', 'N');

sReturn = sReturn.replace('O', 'O');

sReturn = sReturn.replace('P', 'P');

sReturn = sReturn.replace('Q', 'Q');

sReturn = sReturn.replace('R', 'R');

sReturn = sReturn.replace('S', 'S');

sReturn = sReturn.replace('T', 'T');

sReturn = sReturn.replace('U', 'U');

sReturn = sReturn.replace('V', 'V');

sReturn = sReturn.replace('W', 'W');

sReturn = sReturn.replace('X', 'X');

sReturn = sReturn.replace('Y', 'Y');

sReturn = sReturn.replace('Z', 'Z');

sReturn = strReplace(sReturn, "‘", "'");

} catch (Exception ex) {

return sMo;

}

return sReturn;

}

public static synchronized String strReplace(String sAll, String sOld,

String sNew) {

int iT = 0;

String sF = null;

String sH = null;

/* 如果新串中包括旧串,不让替多只让替少 */

if (sNew.indexOf(sOld) != -1) {

return sAll;

}

if ((sAll == null) || (sOld == null) || (sNew == null)) {

return sAll;

}

iT = sAll.indexOf(sOld);

while (iT != -1) {

sF = sAll.substring(0, iT);

sH = sAll.substring(iT + sOld.length());

sAll = sF + sNew + sH;

iT = sAll.indexOf(sOld);

}

return sAll;

}

}

运行结果:

强力清除广告,上网更快的浏览器!

强力清除广告,上网更快的浏览器!

参考:

关于Java转发英文和转发 英语怎么说的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。

The End

发布于:2022-12-03,除非注明,否则均为首码项目网原创文章,转载请注明出处。