求大神解答应该怎么改这段代码,错误:不兼容的类型: String无法转换为char,但是我已经调用toCharArray了
publicclassYanzhengma{char[]datas;publicYanzhengma(){Stringstr="abcdefg1234567890";da...
public class Yanzhengma{
char[] datas;
public Yanzhengma(){
String str="abcdefg1234567890";
datas = str.toCharArray();
}
public char printArray(){
char[] chars=new char[4];
int rand;
for(int i=0;i<chars.length;i++)
{
rand=(int)(Math.random()*chars.length);
chars[i]=datas[rand];
}
return new String (chars);
}
public static void main(String[] args){
Yanzhengma y=new Yanzhengma();
String a=y.printArray();
System.out.println(a);
}
}
错误: 不兼容的类型: String无法转换为char
return new String (chars)
错误: 不兼容的类型: char无法转换为String
String a=y.printArray(); 展开
char[] datas;
public Yanzhengma(){
String str="abcdefg1234567890";
datas = str.toCharArray();
}
public char printArray(){
char[] chars=new char[4];
int rand;
for(int i=0;i<chars.length;i++)
{
rand=(int)(Math.random()*chars.length);
chars[i]=datas[rand];
}
return new String (chars);
}
public static void main(String[] args){
Yanzhengma y=new Yanzhengma();
String a=y.printArray();
System.out.println(a);
}
}
错误: 不兼容的类型: String无法转换为char
return new String (chars)
错误: 不兼容的类型: char无法转换为String
String a=y.printArray(); 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询