求各给大神帮忙啊
import java.util.*;
public class Translate{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
String num = sc.nextLine();
solv(num);
}
private static void solv(String num){
char[] trans = {'零','壹','贰','叁','肆','伍','陆','柒','捌','玖'};
char[] dan ={'拾','佰','仟'};
char[] dan1 = {'万','亿'};
char ch;
int n = 0,l = 0;
int j = 0,temp=0;
int t = 1,c=0, d = 0,f = 0,m=0;
boolean bl = true;
for(int i = 0;i < num.length();i++){
char ch1 = num.charAt(i);
if((ch1 >= '0'&& ch1 <= '9'||ch1 == '.')!= bl){
n++;
break;
}
if(ch1 == '.'){
l++;
d = i;}
if(ch1 >= '0'&&ch1 <= '9'){
c++;
m++;
}
}
if(l > 0)
c = d;
System.out.println(c);
System.out.println(d);
for( j = 0;j < num.length();j++){
if(l > 1||n > 0){
System.out.print("输入错误!!!");
temp++;
break;
}
ch = num.charAt(j);
if(ch >= '0'&& ch <= '9'){
if(ch%48==0){
c--;
if(c == 0&&d!=1)
System.out.print("元");
continue;
}
System.out.print(trans[ch%48]);
if(c==9){
System.out.print(dan1[c / 5]);
c--;
continue;
}
if(c == 5){
System.out.print(dan1[c % 5]);
c--;
continue;
}
if(c-2>=0)
System.out.print(dan[(c-2) % 4]);
}
if(ch != '.')
c--;
else
break;
if(c == 0)
System.out.print("元");
}
if(m-d>0&&num.charAt(d)=='.'&&temp==0){
System.out.print(trans[(num.charAt(d+1)%48)]+"角");
if(m-d>1)
System.out.print(trans[(num.charAt(d+2)%48)]+"分");}
}
}
怎么解决各种“零”情况的出现
public class Translate{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
String num = sc.nextLine();
solv(num);
}
private static void solv(String num){
char[] trans = {'零','壹','贰','叁','肆','伍','陆','柒','捌','玖'};
char[] dan ={'拾','佰','仟'};
char[] dan1 = {'万','亿'};
char ch;
int n = 0,l = 0;
int j = 0,temp=0;
int t = 1,c=0, d = 0,f = 0,m=0;
boolean bl = true;
for(int i = 0;i < num.length();i++){
char ch1 = num.charAt(i);
if((ch1 >= '0'&& ch1 <= '9'||ch1 == '.')!= bl){
n++;
break;
}
if(ch1 == '.'){
l++;
d = i;}
if(ch1 >= '0'&&ch1 <= '9'){
c++;
m++;
}
}
if(l > 0)
c = d;
System.out.println(c);
System.out.println(d);
for( j = 0;j < num.length();j++){
if(l > 1||n > 0){
System.out.print("输入错误!!!");
temp++;
break;
}
ch = num.charAt(j);
if(ch >= '0'&& ch <= '9'){
if(ch%48==0){
c--;
if(c == 0&&d!=1)
System.out.print("元");
continue;
}
System.out.print(trans[ch%48]);
if(c==9){
System.out.print(dan1[c / 5]);
c--;
continue;
}
if(c == 5){
System.out.print(dan1[c % 5]);
c--;
continue;
}
if(c-2>=0)
System.out.print(dan[(c-2) % 4]);
}
if(ch != '.')
c--;
else
break;
if(c == 0)
System.out.print("元");
}
if(m-d>0&&num.charAt(d)=='.'&&temp==0){
System.out.print(trans[(num.charAt(d+1)%48)]+"角");
if(m-d>1)
System.out.print(trans[(num.charAt(d+2)%48)]+"分");}
}
}
怎么解决各种“零”情况的出现
...全文
相关推荐
求模与求余的区别
求模和求余是数学和计算机科学中常见的运算,它们在计算中有着广泛的应用,特别是在数值计算、编码、密码学以及计算机算法设计等领域。这里我们将深入探讨求模和求余的概念,以及它们在不同情况下的行为。
Lua中关于求模与求余的区别介绍
求模和求余的主要区别在于如何处理商的舍入。求模运算时,商被舍入到最接近的整数,但偏向于负无穷小,这样余数的符号始终与除数一致。而求余运算时,商向0方向舍入,使得余数的符号与被除数保持一致。
B样条反求控制点绘制曲线
该项目基于Qt框架实现了一个B样条曲线反求控制点的绘图应用。程序通过矩阵运算反求控制点,支持用户在界面上编辑三维坐标、随机生成数据,并通过滑块调节参数。核心功能包括控制点交互编辑、实时曲线绘制与显示,
C++矩阵求逆
本资源提供的是一种针对多入多出矩阵求逆的实现,这对于机器人系统设计控制算法至关重要。下面将详细讨论矩阵求逆的概念、C++中的实现方式以及在多入多出系统中的应用。
Python求导数的方法
### Python求导数的方法在数学分析中,导数是一个重要的概念,用于描述函数局部线性逼近中的最佳线性近似。Python作为一种强大的编程语言,提供了多种方式来处理数学问题,包括求导数。


