简体   繁体   English

我如何生成文本并自行比较特定文本

[英]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.

相关问题 QueryDSL 如何创建带有自己连接的子查询? - QueryDSL how do I create a SubQuery with its own joins? 如何使用自己的类克隆基于对象的数组列表? - How do I clone a object based arraylist with its own class? 如何将main方法分成自己的类? - How do I seperate main method into its own class? 如何让程序用Java创建自己的变量? - How do I have a program create its own variables with Java? 如何生成特定范围内的随机颜色? - How do I generate a random color in a specific range? 如何在 Java 中生成特定范围内的随机整数? - How do I generate random integers within a specific range in Java? “标题”视图和按钮:如何在没有自己的Activity的“标题”中将监听器附加到按钮? - “Header” Views and buttons: how do I attach listeners to Buttons in a “header” that does not have its own Activity? 如何使用 Java 中的 EditorConfig 在 IntelliJ IDEA 中关闭其自己的行上的右括号? - How do I turn off right-paren on its own line in IntelliJ IDEA with EditorConfig in Java? 如何让Jenkins果冻页面知道其自己的URL? - How Do I get a Jenkins Jelly Page to Know Its Own URL? 如何让程序创建自己的变量以匹配(无限)用户输入? - How do I have a program create its own variables to match (up to an infinite) amount of user inputs?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM