当前位置:好职网>职场指南>面试>JavaEE面试问题(3)

JavaEE面试问题(3)

时间:2019-09-22 11:32:27 面试 我要投稿

JavaEE面试问题汇总(3)

一、 编程题

1. 金额转换,阿拉伯数字的金额转换成中国传统的形式如:(¥1011)->(一千零一拾一元整)输出。

JavaEE面试问题汇总(3)

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 resu<

result = convertToChineseNumber(moneyStr);

result = addUnitsToChineseMoneyString(result);

return resu<

}

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 resu<

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.(i, chineseMoneypattern.get(EMpTY + moneypatternCursor));

moneypatternCursor = moneypatternCursor == 8 ? 1 : moneypatternCursor + 1;

}

String fractionpart = cMoneyStringBuffer.substring(cMoneyStringBuffer.indexOf(\".\"));

cMoneyStringBuffer.(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.(cMoneyStringBuffer.length() - 1, cMoneyStringBuffer.length());

cMoneyStringBuffer.append(fractionpart);

result = cMoneyStringBuffer.toString();

return resu<

}

private String addUnitsToChineseMoneyString(String moneyStr) {

String resu<

StringBuffer cMoneyStringBuffer = new StringBuffer(moneyStr);

int indexOfDot = cMoneyStringBuffer.indexOf(DOT);

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

2. Java的通信编程,编程题(或问答),用JAVASOCKET编程,读服务器几个字符,再写入本地显示?

:Server端程序:
packagetest;
importjava.net.*;
importjava.io.*;
publicclassServer
{
privateServerSocketss;
privateSocketsocket;
privateBufferedReaderin;
privateprintWriterout;
publicServer()
{
try
{
ss=newServerSocket(10000);
while(true)
{
socket=ss.accept();
StringRemoteIp=socket.getInetAddress().getHostAddress();
StringRemoteport=\":\"+socket.getLocalport();
System.out.println(\"Aclientcomein!Ip:\"+RemoteIp+Remoteport);
in=newBufferedReader(new
InputStreamReader(socket.getInputStream()));
Stringline=in.readLine();
System.out.println(\"Cleintsendis:\"+line);
out=newprintWriter(socket.getOutputStream(),true);
out.println(\"YourMessageReceived!\");
out.close();
in.close();
socket.close();
}
}catch(IOExceptione)
{
out.println(\"wrong\");
}
}
publicstaticvoidmain(String[]ar

【JavaEE面试问题汇总(3)】相关文章:

1.面试问题汇总

2.7.28面试问题3

3.空姐面试问题汇总

4.关于面试怪异问题汇总

5.求职面试问题汇总

6.php面试问题汇总

7.英文面试问题汇总

8.面试棘手问题3招破解