L1-007 念数字
import java.util.Scanner;
public class L1007{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String num = sc.next();
//定义数组,通过索引值确定数字与拼音的对应关系
String[] str = {"ling","yi","er","san","si","wu","liu","qi","ba","jiu"};
//索引值从0开始
int i = 0;
//如果读入的第一个字符为‘-’则为负数输出“fu”
if(num.charAt(0) == '-'){
System.out.print("fu ");
i++;
}
//开始逐一读取
while(i<num.length()){
//将字符转化为对应的索引值
int n = num.charAt(i) - '0';
//输出索引值对应的字符
System.out.print(str[n]);
i++;
//最后一个空格不输出
if(n != num.length()){
System.out.print(" ");
}
}
}
}
我严重怀疑PTA歧视java,用C怎么都不错,java每天报一万次格式错误,我实在是找不出来哪里格式错了,甚至连多余的空格都没有一个了还报格式错误,谁来救救孩子,这个问题怎么解决!!!