CS1103 unit 2 - Random Sentence generator program

Pubblicato il: 28 giugno 2023
sul canale di: Web Development
307
2

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.


In questa pagina del sito puoi guardare il video online CS1103 unit 2 - Random Sentence generator program della durata di ore minuti seconda in buona qualità , che l'utente ha caricato Web Development 28 giugno 2023, condividi il link con amici e conoscenti, su youtube questo video è già stato visto 307 volte e gli è piaciuto 2 spettatori. Buona visione!