[英]how do i generate texts and comparing a specific text on its own
I do not know how to work on the following problem (How can I print each letter of the entered word at the end of each randomly generated word and the single letter of the entered word can be repeated more than once and take the letters from the entered word randomly while ensuring that all the letters of the entered word are taken And print them out)我不知道如何解决以下问题(如何在每个随机生成的单词末尾打印输入单词的每个字母,并且输入单词的单个字母可以重复多次,并从随机输入单词,同时确保输入单词的所有字母都被取出并打印出来)
Example:例子:
input:输入:
name = "adel"
output: output:
lkjljl a
sdada l
lkkjlkj l
werwrew d
oioiu e
What I have so far:到目前为止我所拥有的:
public void Gen(String name) {
Random r = new Random();
String alphabet = "abcdefghijklmnopqrstuvwxyz";
for (int j = 0; j < name.length(); j++) {
for (int i = 0; i < alphabet.charAt(r.nextInt(alphabet.length())) % 30; i++) {
System.out.print(alphabet.charAt(r.nextInt(alphabet.length())));
}
char g = name.charAt(j);
System.out.println(g);
}
}
In your second for
loop,在你的第二个for
循环中,
for (int i = 0; i < alphabet.charAt(r.nextInt(alphabet.length())) % 30; i++)
alphabet.charAt(r.nextInt(alphabet.length()))
gives you String
, not int
, so there's an error there. alphabet.charAt(r.nextInt(alphabet.length()))
给你String
,而不是int
,所以那里有一个错误。 You can just remove alphabet.charAt()
.您可以删除alphabet.charAt()
。
Also, On your print
statement, it generate another random number, which can be different than the one in the second for
loop.此外,在您的print
语句中,它会生成另一个随机数,该随机数可能与第二个for
循环中的随机数不同。
public void Gen(String name) {
Random r = new Random();
String alphabet = "abcdefghijklmnopqrstuvwxyz";
for (int j = 0; j < name.length(); j++)
{
System.out.print(alphabet.charAt(r.nextInt(alphabet.length())));
char g = name.charAt(j);
System.out.println(g);
}
}
I do not know how to work on the following problem (How can I print each letter of the entered word at the end of each randomly generated word and the single letter of the entered word can be repeated more than once and take the letters from the entered word randomly while ensuring that all the letters of the entered word are taken And print them out)我不知道如何解决以下问题(如何在每个随机生成的单词的末尾打印输入单词的每个字母,并且输入单词的单个字母可以重复多次并从随机输入的单词,同时确保输入单词的所有字母都被取出并打印出来)
Example:例子:
input:输入:
name = "adel"
output: output:
lkjljl a
sdada l
lkkjlkj l
werwrew d
oioiu e
What I have so far:到目前为止我所拥有的:
public void Gen(String name) {
Random r = new Random();
String alphabet = "abcdefghijklmnopqrstuvwxyz";
for (int j = 0; j < name.length(); j++) {
for (int i = 0; i < alphabet.charAt(r.nextInt(alphabet.length())) % 30; i++) {
System.out.print(alphabet.charAt(r.nextInt(alphabet.length())));
}
char g = name.charAt(j);
System.out.println(g);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.