一级做a爱片,色站综合,99偷拍视频精品一区二区,亚洲精品色无码AV

當前位置:

JAVA認證《專業(yè)語言》編程模擬題排序和金額轉換

發(fā)表時間:2015/4/13 11:28:21 來源:互聯網 點擊關注微信:關注中大網校微信
關注公眾號

1.現在輸入n個數字,以逗號,分開;然后可選擇升或者降序排序;按提交鍵就在另一頁面顯示按什么排序,結果為,提供reset

import java.util.*;

public class bycomma{

public static String[] splitStringByComma(String source){

if(source==null||source.trim().equals(""))

return null;

StringTokenizer commaToker = new StringTokenizer(source,",");

String[] result = new String[commaToker.countTokens()];

int i=0;

while(commaToker.hasMoreTokens()){

result[i] = commaToker.nextToken();

i++;

}

return result;

}

public static void main(String args[]){

String[] s = splitStringByComma("5,8,7,4,3,9,1");

int[] ii = new int[s.length];

for(int i = 0;i

ii[i] =Integer.parseInt(s[i]);

}

Arrays.sort(ii);

//asc

for(int i=0;i

System.out.println(ii[i]);

}

//desc

for(int i=(s.length-1);i>=0;i--){

System.out.println(ii[i]);

}

}

}

2.金額轉換,阿拉伯數字的金額轉換成中國傳統(tǒng)的形式如:(¥1011)->(一千零一拾一元整)輸出。

package test.format;

import java.text.NumberFormat;

import java.util.HashMap;

public class SimpleMoneyFormat {

public static final String EMPTY = "";

public static final String ZERO = "零";

public static final String ONE = "壹";

public static final String TWO = "貳";

public static final String THREE = "叁";

public static final String FOUR = "肆";

public static final String FIVE = "伍";

public static final String SIX = "陸";

public static final String SEVEN = "柒";

public static final String EIGHT = "捌";

public static final String NINE = "玖";

public static final String TEN = "拾";

public static final String HUNDRED = "佰";

public static final String THOUSAND = "仟";

public static final String TEN_THOUSAND = "萬";

public static final String HUNDRED_MILLION = "億";

public static final String YUAN = "元";

public static final String JIAO = "角";

public static final String FEN = "分";

public static final String DOT = ".";

private static SimpleMoneyFormat formatter = null;

private HashMap chineseNumberMap = new HashMap();

private HashMap chineseMoneyPattern = new HashMap();

private NumberFormat numberFormat = NumberFormat.getInstance();

private SimpleMoneyFormat() {

numberFormat.setMaximumFractionDigits(4);

numberFormat.setMinimumFractionDigits(2);

numberFormat.setGroupingUsed(false);

chineseNumberMap.put("0", ZERO);

chineseNumberMap.put("1", ONE);

chineseNumberMap.put("2", TWO);

chineseNumberMap.put("3", THREE);

chineseNumberMap.put("4", FOUR);

chineseNumberMap.put("5", FIVE);

chineseNumberMap.put("6", SIX);

chineseNumberMap.put("7", SEVEN);

chineseNumberMap.put("8", EIGHT);

chineseNumberMap.put("9", NINE);

chineseNumberMap.put(DOT, DOT);

chineseMoneyPattern.put("1", TEN);

chineseMoneyPattern.put("2", HUNDRED);

chineseMoneyPattern.put("3", THOUSAND);

chineseMoneyPattern.put("4", TEN_THOUSAND);

chineseMoneyPattern.put("5", TEN);

chineseMoneyPattern.put("6", HUNDRED);

chineseMoneyPattern.put("7", THOUSAND);

chineseMoneyPattern.put("8", HUNDRED_MILLION);

}

public static SimpleMoneyFormat getInstance() {

if (formatter == null)

formatter = new SimpleMoneyFormat();

return formatter;

}

public String format(String moneyStr) {

checkPrecision(moneyStr);

String result;

result = convertToChineseNumber(moneyStr);

result = addUnitsToChineseMoneyString(result);

return result;

}

public String format(double moneyDouble) {

return format(numberFormat.format(moneyDouble));

}

public String format(int moneyInt) {

return format(numberFormat.format(moneyInt));

}

public String format(long moneyLong) {

return format(numberFormat.format(moneyLong));

}

public String format(Number moneyNum) {

return format(numberFormat.format(moneyNum));

}

private String convertToChineseNumber(String moneyStr) {

String result;

StringBuffer cMoneyStringBuffer = new StringBuffer();

for (int i = 0; i < moneyStr.length(); i++) {

cMoneyStringBuffer.append(chineseNumberMap.get(moneyStr.substring(i, i + 1)));

}

//拾佰仟萬億等都是漢字里面才有的單位,加上它們

int indexOfDot = cMoneyStringBuffer.indexOf(DOT);

int moneyPatternCursor = 1;

for (int i = indexOfDot - 1; i > 0; i--) {

cMoneyStringBuffer.insert(i, chineseMoneyPattern.get(EMPTY + moneyPatternCursor));

moneyPatternCursor = moneyPatternCursor == 8 ? 1 : moneyPatternCursor + 1;

}

String fractionPart = cMoneyStringBuffer.substring(cMoneyStringBuffer.indexOf("."));

cMoneyStringBuffer.delete(cMoneyStringBuffer.indexOf("."), cMoneyStringBuffer.length());

while (cMoneyStringBuffer.indexOf("零拾") != -1) {

cMoneyStringBuffer.replace(cMoneyStringBuffer.indexOf("零拾"), cMoneyStringBuffer.indexOf("零拾") + 2, ZERO);

}

while (cMoneyStringBuffer.indexOf("零佰") != -1) {

cMoneyStringBuffer.replace(cMoneyStringBuffer.indexOf("零佰"), cMoneyStringBuffer.indexOf("零佰") + 2, ZERO);

}

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, HUNDRED_MILLION);

}

while (cMoneyStringBuffer.indexOf("零零") != -1) {

cMoneyStringBuffer.replace(cMoneyStringBuffer.indexOf("零零"), cMoneyStringBuffer.indexOf("零零") + 2, ZERO);

}

if (cMoneyStringBuffer.lastIndexOf(ZERO) == cMoneyStringBuffer.length() - 1)

cMoneyStringBuffer.delete(cMoneyStringBuffer.length() - 1, cMoneyStringBuffer.length());

cMoneyStringBuffer.append(fractionPart);

result = cMoneyStringBuffer.toString();

return result;

}

private String addUnitsToChineseMoneyString(String moneyStr) {

String result;

StringBuffer cMoneyStringBuffer = new StringBuffer(moneyStr);

int indexOfDot = cMoneyStringBuffer.indexOf(DOT);

cMoneyStringBuffer.replace(indexOfDot, indexOfDot + 1, YUAN);

}

編輯推薦:

JAVA認證考試報考指南 / 更多JAVA考試模擬試題

(責任編輯:xy)

2頁,當前第1頁  第一頁  前一頁  下一頁
最近更新 考試動態(tài) 更多>
国产亚洲不卡外卖| 无码中文不卡高清| 色狠狠一区| 欧美日韩看激情在线| 日韩大片免费观看视频播放| 亚洲色老汉av在线| 日韩中文人妻| 日韩视频精品在线一区| 亚洲中文字幕久久精品无码2021| 亚洲毛片高清| 午夜激情无码| 欧美丝袜人妻日韩| 国产日韩欧美亚欧在线| 性按摩无码在线| AV网站在线看| 草AV在线| 亚洲综合一区二区三区| 日韩久久大香蕉| 日韩AV在线免费看| 999久久久精品播放| 天柱县| 超91久久福利视频| 日韩欧美国产一中文字暮精品| 3久狠狠| 新东京热亚洲色图| 午夜黄色网站在线观看| 91精品系列| 日韩一本无码| 日韩啪啪资源| 久久精品国产亚洲不AV麻豆| 99久久玖玖| 18禁无遮挡国产免费观看| 四虎电影链接| 91欧美一区二区| 一级性爱免费播放| 99热精品久久只有精品| 久久av人| 最新av| 少妇免费不卡视频| 制服一区| 久久久欧洲国产|