L1-007 念数字 (10 分)java![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/6b32ccf814ec8e236918a6512cab2455.png)
1、定义一个数组并按顺序存放0-9的拼音
2、使用if将正数与负数分离
3、用循环将字符串进行遍历。注意:负数要进行Math.abs()转换,并且需要在前面输出“fu”
import java.util.Scanner;
public class pta3 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int a = in.nextInt();
String b;
String c[] = { "ling", "yi", "er", "san", "si", "wu", "liu", "qi", "ba", "jiu" };
char d = 0;
int e = 0;
if (a < 0) {
System.out.print("fu" + "");
a = Math.abs(a);
b = a + "";
for (int i = 0; i < b.length(); i++) {
d = b.charAt(i);
e = d - '0';
System.out.print(" " + c[e]);
}
} else {
b = a + "";
for (int i = 0; i < b.length(); i++) {
d = b.charAt(i);
e = d - '0';
if (i == 0) {
System.out.print(c[e] + "");
} else {
System.out.print(" " + c[e]);
}
}
}
}
}