java程序的问题- -U
public void convert3(String str){int a[]={0,1,2,3,4,5,6,7,8,9,10};String b[]={"零","一","二","三","四","五","六","七","八","九","十","百"};if(str.charAt(1)=='十'){String s = String.valueOf(str.charAt(0));String s1 = String.valueOf(str.charAt(2));int ten;int sig;for(int i=0;i<11;i++){if(s.equals(b[i])){ten=a[i];}if(s1.equals(b[i])){sig=a[i];}System.out.println("您要转换的数是:"+str+" "+"转换的结果是:"+(ten*10+sig));}}}这个函数中我需要参数ten和sig但是,这么运行的错误却是说这两个参数没有初始化...我应该怎么改啊
参考答案:public void convert3(String str)
{
int a[]={0,1,2,3,4,5,6,7,8,9,10},ten=0,sig=0;
String b[]={"零","一","二","三","四","五","六","七","八","九","十","百"};
if(str.charAt(1)=='十')
{
String s = String.valueOf(str.charAt(0));
String s1 = String.valueOf(str.charAt(2));
for(int i=0;i<11;i++)
{
if(s.equals(b[i]))
{
ten=a[i];
}
if(s1.equals(b[i]))
{
sig=a[i];
}
System.out.println("您要转换的数是:"+str+" "+"转换的结果是:"+(ten*10+sig));
}
}
}
这样就行了