求java高手帮忙解决一下
现有一个字符串数组match={“computer”,”depart”,”our”,”goal”},利用随机数函数Math.random()(0到1之间的小数)生成的单词...
现有一个字符串数组match={“computer”,”depart”,”our”,”goal”},利用随机数函数Math. random()(0到1之间的小数)生成的单词与数组中的元素进行匹配,输出匹配的结果
public class Pipei {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
String[] match={"computer","depart","our","goal"};
int randomNumber=(int)(Math.random()*27)+97;
for (int j = 0; j <= match.length; j++){
char a[];
a[j]=(char)randomNumber;
}
String s=new String(a);
for(int i=0;i<=3;i++){
if(match[i].equals(s)){
System.out.println("相匹配");
}
}
}
}
帮忙改一下错吧,谢谢了 展开
public class Pipei {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
String[] match={"computer","depart","our","goal"};
int randomNumber=(int)(Math.random()*27)+97;
for (int j = 0; j <= match.length; j++){
char a[];
a[j]=(char)randomNumber;
}
String s=new String(a);
for(int i=0;i<=3;i++){
if(match[i].equals(s)){
System.out.println("相匹配");
}
}
}
}
帮忙改一下错吧,谢谢了 展开
2个回答
展开全部
public class Pipei{
public static void main(String[] args) {
String[] match={"computer","depart","our","goal"};
for(int i = 0; i <=3; i++){
char c;
String s = "";
for (int j = 0; j <= match[i].length(); j++){
int randomNumber=(int)(Math.random()*27)+97;
c = (char)randomNumber;
s += c;
}
if(match[i].equals(s))
System.out.println("相匹配");
else
System.out.println("不匹配");
}
}
}
输出结果是“相匹配”的可能性是很小的!
public static void main(String[] args) {
String[] match={"computer","depart","our","goal"};
for(int i = 0; i <=3; i++){
char c;
String s = "";
for (int j = 0; j <= match[i].length(); j++){
int randomNumber=(int)(Math.random()*27)+97;
c = (char)randomNumber;
s += c;
}
if(match[i].equals(s))
System.out.println("相匹配");
else
System.out.println("不匹配");
}
}
}
输出结果是“相匹配”的可能性是很小的!
展开全部
public static void main(String[] args) {
// TODO Auto-generated method stub
String[] match={"computer","depart","our","goal"};
char a[]=new char[match.length];
for (int j = 0; j < match.length; j++){
int randomNumber=(int)(Math.random()*26)+97;
a[j]=(char)randomNumber;
//System.out.println(a[j]);
}
String s=new String(a);
System.out.println(s);
for(int i=0;i<match.length;i++){
if(match[i].equals(s)){
System.out.println("相匹配");
}
}
}
// TODO Auto-generated method stub
String[] match={"computer","depart","our","goal"};
char a[]=new char[match.length];
for (int j = 0; j < match.length; j++){
int randomNumber=(int)(Math.random()*26)+97;
a[j]=(char)randomNumber;
//System.out.println(a[j]);
}
String s=new String(a);
System.out.println(s);
for(int i=0;i<match.length;i++){
if(match[i].equals(s)){
System.out.println("相匹配");
}
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询