gpt4 book ai didi

java - cmd 一直告诉我错误找不到符号

转载 作者:行者123 更新时间:2023-12-02 06:07:48 25 4
gpt4 key购买 nike

我已经尝试了几天来运行这个,但由于某种原因它没有成功。这是代码:强文本

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);

}

}

最佳答案

你有两个错误。

字符串带有“S”,而不是“s”

并且在您的Stringphrase=中,您没有将“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);

}

关于java - cmd 一直告诉我错误找不到符号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22135823/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com