임의의 Haikus를 생성하는 프로그램을 작성해야합니다. 내 계획은 지정된 수의 음절 명사, 동사 및 형용사가 포함 된 파일로 프로그램을 읽는 것이지만 코딩에 문제가 있습니다. 지금은 다음과 같습니다 : 나는 단지 "는"형용사 부분을 얻고 내 출력을 위해Haiku Generator Java
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)]);
}
}
}
은. 왜 이런거야?
오, 그래, 나는 그 순간에 정확하게 첫 줄을 인쇄하는 중이다.
'gen'은 어디에 정의되어 있습니까? – gparyani
임의 생성 = 새로운 임의(); – user2149738