Function sentence():
Generate a simple sentence
If randomly chosen True:
conjunctions = ["and", "or", "but", "because"]
conjunction = Randomly select a conjunction from the list
Print conjunction + " "
Generate another sentence
The sentence function generates a random sentence. If randomly chosen to be true, it selects a conjunction and generates another sentence recursively. In Java, the equivalent code would be:
public static void sentence() {
simpleSentence();
if (randomlyChooseTrue()) {
String[] conjunctions = {"and", "or", "but", "because"};
String conjunction = randomItem(conjunctions);
System.out.print(conjunction + " ");
sentence();
}
}
Please leave a comment about this video using CS1103 in your comment and your email to get the rest of the Algorithm / code.
Auf dieser Seite können Sie das Online-Video CS1103 unit 2 - Random Sentence generator program mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer Web Development 28 Juni 2023 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 307 Mal angesehen und es wurde von 2 den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!