一JAVA笔试题,牛人都来哈!方面越简单人越牛。

leiyongekin 2006-10-19 12:32:19
题目:要求从键盘输入一数字,然后中文输出(要符合中文语法)
例:12434 输出 一万二千四百三十四
...全文
6256 115 打赏 收藏 转发到动态 举报
写回复
用AI写文章
115 条回复
切换为时间正序
请发表友善的回复…
发表回复
wy158457 2006-11-14
  • 打赏
  • 举报
回复
mark
master0908 2006-11-14
  • 打赏
  • 举报
回复
这么多牛人,厉害
lookfor63 2006-11-14
  • 打赏
  • 举报
回复
我也贴一个供大家参考:
public static String changeNumToUpCase( double dSrcValue )
{
String sUnit[] = new String[] { "", "拾", "佰", "仟" };
String sNumber[] = new String[] { "零", "壹", "贰", "叁", "肆", "伍", "陆",
"柒", "捌", "玖" };
StringBuffer sDstValue = new StringBuffer();
double dTempValue;
//计算数值的长度,每4位为一个长度(除去小数部分)
int iLength = (int) ((new DecimalFormat("#").format(dSrcValue).length() + 3) / 4);

//每次取四位为一个数值
int iValue = 0;

//每次取一位的数值
int iBitValue;

//前一次的数值
int iPreValue = 1000;

int iLoop;
int iLoop2;

//标记该次取的4位数值是否为0
boolean flag1 = false;

//标志该次取的1位数值是否为0
boolean flag2 = false;

//取小数部分,保留两位小数(四舍五入)
dTempValue = Math.round((dSrcValue - Math.floor(dSrcValue)) * 100);
iBitValue = (int) dTempValue % 10;

//算分
if ( iBitValue > 0 )
{
sDstValue.append("分" + sNumber[iBitValue]);
}
iBitValue = (int) dTempValue / 10;
//算角
if ( iBitValue > 0 )
{
sDstValue.append("角" + sNumber[iBitValue]);
}

sDstValue.append("圆");

dTempValue = dSrcValue;

//每次取4位作为1个单元进行处理
for ( iLoop = 0; iLoop < iLength; iLoop++ )
{
//取末4位数值
iValue = (int) (dTempValue % 10000);

//缩小4倍
dTempValue = Math.floor(dTempValue / 10000);
//如果之前的值为0或不足4位并且当前值不为0则附加一位0
if ( (iPreValue < 1000 && iPreValue > 0)
|| (iValue <= 0 && flag1 == true) )
{
sDstValue.append("零");
}
//将前一次的值设为当前值
iPreValue = iValue;

//如果当前值不为0或者达到亿以上时则附加一个单位
if ( iValue > 0 || iLoop >= 2 )
{
//当前值为亿
if ( iLoop == 2 )
{
sDstValue.append("亿");
}
//其它值的情况
else if ( iLoop > 0 )
{
sDstValue.append("万");
}
}
else
{
continue;
}

//标志当前值是否为0
flag1 = (iValue > 0 ? true : false);

iLoop2 = 0;
flag2 = false;

//依次处理4位中的每一位数值
while ( iValue > 0 )
{
iBitValue = iValue % 10;
iValue = iValue / 10;
//如果之前为0则附加一位0
if ( iBitValue <= 0 && flag2 == true )
{
sDstValue.append("零");
}
//附加转换为大写后的数值及单位
if ( iBitValue > 0 )
{
sDstValue.append(sUnit[iLoop2]);
sDstValue.append(sNumber[iBitValue]);
flag2 = true;
}
else
{
flag2 = false;
}
iLoop2++;
}
}

System.out.print(sDstValue.reverse().toString() + "整");
//返回转换后的值
return sDstValue.toString() + "整";
}
hihendry 2006-11-14
  • 打赏
  • 举报
回复
mark
zhuixun5506 2006-11-13
  • 打赏
  • 举报
回复
学习
skorpi 2006-11-13
  • 打赏
  • 举报
回复
mark
wangbiao 2006-11-13
  • 打赏
  • 举报
回复
mark
RichardCo 2006-11-13
  • 打赏
  • 举报
回复
很有用的程序哦
fishyqd 2006-11-13
  • 打赏
  • 举报
回复
笔试的时候碰到过,不过要用C实现
jackxing 2006-11-13
  • 打赏
  • 举报
回复
mark
brant_yan 2006-11-13
  • 打赏
  • 举报
回复
http://promosearch.atomz.com 里面哪里有代码可以看啊。。怎么没找到。。
muziyi0208 2006-11-12
  • 打赏
  • 举报
回复
学习ing。。。。。。
abpeng 2006-11-12
  • 打赏
  • 举报
回复
mark
rgb_rgb 2006-11-12
  • 打赏
  • 举报
回复
remark
吴冬冬 2006-11-12
  • 打赏
  • 举报
回复
/**输入整型数值,输出汉字形式
完整程序,通过测试
记得给分哦*/
import java.io.*;

class Change{
public static String change(String str){
String chn="零一二三四五六七八九";
String chm="十亿千百十万千百十";

StringBuffer strb=new StringBuffer(str);
for(int i=0;i<str.length();i++){
strb.setCharAt(i, chn.charAt(Integer.parseInt(Character.toString(str.charAt(i)))));
}
String temp=chm.substring(chm.length()-str.length()+1);
int n=strb.length();
for(int j=0;j<n-1;j++){
strb.insert(2*j+1, temp.charAt(j));
}
strb.append('个');
for(int p=0;p<3;p++){
for(int k=0;k<strb.length();k++){
if(strb.charAt(k)=='零'){
if(strb.charAt(k+1)=='万' || strb.charAt(k+1)=='亿' || strb.charAt(k+1)=='个'){
strb.setCharAt(k,'0');
}else if(strb.charAt(k+1)=='千' || strb.charAt(k+1)=='百' || strb.charAt(k+1)=='十'){
strb.setCharAt(k+1,'0');
}
}
}
for(int k=0;k<strb.length();k++){
if(strb.charAt(k)=='0'){
strb.deleteCharAt(k);
k--;
}
}
}
strb.deleteCharAt(strb.length()-1);
return strb.toString();
}
}
public class ChineseTest {
public static void main(String[] args)throws IOException{
BufferedReader rd=new BufferedReader(new InputStreamReader(System.in));
System.out.println("将数字转化为汉字输出(quit退出)");
while(true){
System.out.print(">");
String line=rd.readLine();
while(line.equals("quit")){
break;
}
System.out.println(Change.change(line));
}
}
}
nicky_hk 2006-11-11
  • 打赏
  • 举报
回复
mark
ferreousbox 2006-11-09
  • 打赏
  • 举报
回复
一楼的PL,哈哈~~
linzhongren 2006-11-09
  • 打赏
  • 举报
回复
mark
zsh6709 2006-11-09
  • 打赏
  • 举报
回复
to lip009(深蓝忧郁)

还有bug
就是输入类似 000.23时
zsh6709 2006-11-09
  • 打赏
  • 举报
回复
支持深蓝
加载更多回复(95)

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧