Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/334.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
俳句生成器Java_Java_Arrays - Fatal编程技术网

俳句生成器Java

俳句生成器Java,java,arrays,Java,Arrays,我需要写一个生成随机俳句的程序。我的计划是让程序读入包含指定数量的音节名词、动词和形容词的文件,但我在编码方面遇到了问题。现在看起来是这样的: package poetryproject; import java.io.File; import java.io.FileNotFoundException; import java.util.Random; import java.util.Scanner; public class PoetryProject { public

我需要写一个生成随机俳句的程序。我的计划是让程序读入包含指定数量的音节名词、动词和形容词的文件,但我在编码方面遇到了问题。现在看起来是这样的:

package poetryproject;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.Random;
import java.util.Scanner;



public class PoetryProject {

    public static void main(String[] args) throws FileNotFoundException {


        Random gen = new Random();

        Scanner adjectivesFile = new Scanner(new File("AdjectivesFile.dat"));
        Scanner nounFile = new Scanner(new File("NounFile.dat"));
        Scanner verbFile = new Scanner(new File("VerbFile.dat"));

        int adjectiveCount = adjectivesFile.nextInt();
        String[] adjectiveList = new String[adjectiveCount];
        for (int i = 0; i < adjectiveCount; i++) {
            adjectiveList[i] = adjectivesFile.nextLine();
        }
        adjectivesFile.close();

        int nounCount = nounFile.nextInt();
        String[] nounList = new String[nounCount];
        for (int i = 0; i < nounCount; i++) {
            nounList[i] = nounFile.nextLine();
        }
        nounFile.close();

        int verbCount = verbFile.nextInt();
        String[] verbList = new String[verbCount];
        for (int i = 0; i < verbCount; i++) {
            verbList[i] = verbFile.nextLine();
        }
        verbFile.close();

        for (int count = 1; count <= 1; count++) {
           System.out.printf("The %s %s \n",       adjectiveList[gen.nextInt(adjectiveList.length)]);
        }
        for (int count = 1; count <= 1; count++) {
            System.out.printf("%s %s \n", nounList[gen.nextInt(nounList.length)]);
        }
        for (int count = 1; count <= 1; count++) {
            System.out.printf("%s %s \n", verbList[gen.nextInt(verbList.length)]);
        }
     }
}
package项目;
导入java.io.File;
导入java.io.FileNotFoundException;
导入java.util.Random;
导入java.util.Scanner;
公共类项目{
公共静态void main(字符串[]args)引发FileNotFoundException{
Random gen=新的Random();
Scanner形容词文件=新扫描仪(新文件(“形容词文件.dat”);
Scanner nounFile=新扫描仪(新文件(“nounFile.dat”);
Scanner verbFile=新扫描仪(新文件(“verbFile.dat”);
int形容词计数=形容词文件.nextInt();
字符串[]形容词列表=新字符串[形容词计数];
for(int i=0;i对于(int count=1;count第一个
printf()
的格式说明符与参数不匹配:

System.out.printf("The %s %s \n", adjectiveList[gen.nextInt(adjectiveList.length)]);

这将抛出一个错误,在打印形容词部分后过早结束程序。

第一个
printf()
的格式说明符与参数不匹配:

System.out.printf("The %s %s \n", adjectiveList[gen.nextInt(adjectiveList.length)]);

这将抛出一个,在打印形容词部分后过早结束程序。

因为您尚未为System.out.printf生成的参数指定第二个参数 在第行找不到符号错误:

System.out.printf("The %s %s \n",adjectiveList[gen.nextInt(adjectiveList.length)]);
                          ^
删除第二个格式说明符并按如下方式写入:

System.out.printf("The %s\n",       adjectiveList[gen.nextInt(adjectiveList.length)]);

这应该可以解决您的问题。

因为您没有为System.out.printf生成的参数指定第二个参数 在第行找不到符号错误:

System.out.printf("The %s %s \n",adjectiveList[gen.nextInt(adjectiveList.length)]);
                          ^
删除第二个格式说明符并按如下方式写入:

System.out.printf("The %s\n",       adjectiveList[gen.nextInt(adjectiveList.length)]);

这应该可以解决您的问题。

哪里定义了
gen
随机gen=new Random();哪里定义了
gen
随机gen=new Random();该方法正在等待2个参数格式化,而您仅从列表中传递1个形容词。请删除一个
%s
,或在形容词后添加另一个参数。这很容易。谢谢!该方法正在等待2个参数格式化,而您仅从列表中传递1个形容词。请删除一个
%s
>或者在形容词后面加上另一个论点。好吧,该死,那很简单。谢谢!