排序和金额转换·两道JAVA编程题及答案
来源:长理培训发布时间:2017-12-19 10:37:46
百度广告
1.现在输入n个数字,以逗号,分开;然后可选择升或者降序排序;按提交键就在另一页面显示按什么排序,结果为,提供reset
import java.util.*;
public static String splitStringByComma(String source){
return null;
String result = new String[commaToker.countTokens()];
while(commaToker.hasMoreTokens()){
i++;
return result;
public static void main(String args){
int ii = new int[s.length];
import java.text.NumberFormat;
public class SimpleMoneyFormat {
public static final String ZERO = "零";
public static final String TWO = "贰";
public static final String FOUR = "肆";
public static final String SIX = "陆";
public static final String EIGHT = "捌";
public static final String TEN = "拾";
public static final String THOUSAND = "仟";
public static final String HUNDRED_MILLION = "亿";
public static final String JIAO = "角";
public static final String DOT = ".";
private HashMap chineseNumberMap = new HashMap();
private NumberFormat numberFormat = NumberFormat.getInstance();
numberFormat.setMaximumFractionDigits(4);
numberFormat.setGroupingUsed(false);
chineseNumberMap.put("1", ONE);
chineseNumberMap.put("3", THREE);
chineseNumberMap.put("5", FIVE);
chineseNumberMap.put("7", SEVEN);
chineseNumberMap.put("9", NINE);
chineseMoneyPattern.put("1", TEN);
chineseMoneyPattern.put("3", THOUSAND);
chineseMoneyPattern.put("5", TEN);
chineseMoneyPattern.put("7", THOUSAND);
}
if (formatter == null)
return formatter;
public String format(String moneyStr) {
String result;
result = addUnitsToChineseMoneyString(result);
}
return format(numberFormat.format(moneyDouble));
public String format(int moneyInt) {
}
return format(numberFormat.format(moneyLong));
public String format(Number moneyNum) {
}
String result;
for (int i = 0; i 0; i--) {
moneyPatternCursor = moneyPatternCursor == 8 ? 1 : moneyPatternCursor + 1;
String fractionPart = cMoneyStringBuffer.substring(cMoneyStringBuffer.indexOf("."));
while (cMoneyStringBuffer.indexOf("零拾") != -1) { |||
}
cMoneyStringBuffer.replace(cMoneyStringBuffer.indexOf("零佰"), cMoneyStringBuffer.indexOf("零佰") + 2, ZERO);
while (cMoneyStringBuffer.indexOf("零仟") != -1) {
}
cMoneyStringBuffer.replace(cMoneyStringBuffer.indexOf("零万"), cMoneyStringBuffer.indexOf("零万") + 2, TEN_THOUSAND);
while (cMoneyStringBuffer.indexOf("零亿") != -1) {
}
cMoneyStringBuffer.replace(cMoneyStringBuffer.indexOf("零零"), cMoneyStringBuffer.indexOf("零零") + 2, ZERO);
if (cMoneyStringBuffer.lastIndexOf(ZERO) == cMoneyStringBuffer.length() - 1)
cMoneyStringBuffer.append(fractionPart);
return result;
private String addUnitsToChineseMoneyString(String moneyStr) {
StringBuffer cMoneyStringBuffer = new StringBuffer(moneyStr);
cMoneyStringBuffer.replace(indexOfDot, indexOfDot + 1, YUAN);
点击加载更多评论>>