我现在已经尝试了几天来运行它,但由于某种原因它没有通过。这是代码:强文
public class namegenerator {
public static void main(string[] args) {
string[] firstnames = {"James", "Philip", "Danny", "Bob", "joshua"};
string[] lastnames = {"Franklin", "Hunter", "Johnson", "Smith", "Jones"};
int onelength = firstnames.length;
int twolength = lastnames.length;
int rand1 = (int) (Math.random() * onelength);
int rand2 = (int) (Math.random() * twolength);
String phrase = firstname [rand1] + " " + lastname [rand2];
System.out.println("Your fake name is, " + phrase);
}
}
答案 0 :(得分:2)
你有两个错误。
字符串是“S”,而不是“s”
在你的String phrase=
中,你没有将“s”添加到“firstname”
public static void main(String[] args) {
String[] firstnames = {"James", "Philip", "Danny", "Bob", "joshua"};
String[] lastnames = {"Franklin", "Hunter", "Johnson", "Smith", "Jones"};
int onelength = firstnames.length;
int twolength = lastnames.length;
int rand1 = (int) (Math.random() * onelength);
int rand2 = (int) (Math.random() * twolength);
String phrase = firstnames[rand1] + " " + lastnames[rand2];
System.out.println("Your fake name is, " + phrase);
}
答案 1 :(得分:0)
主方法声明中有一个拼写错误,类名是字符串而不是字符串
public static void main(String args[])