r/JavaProgramming • • 1d ago

Any help on how to improve this?

void main(String[] args) {
    Random rand = new Random();

    // 1. Single 'int' (no brackets), starting at 1 so it always prints at least one word
    int words = rand.nextInt(1, 10);
    int[] arrayofrandomint = new int[words];
    Scanner input = new Scanner(System
in
);
    String wordslist = " This is an actual pargraphing creting AI, it generates" +
            "text and predicts what the next word will be depending on how many" +
            "other words are around it.";
    String[] newdata = wordslist.toLowerCase(Locale.
ROOT
).trim().split(" ");



    for (int i = 0; i < words; i++) {
        //String currentWord = wordslist[rand.nextInt(0, wordslist.length)];
        // While in the for loop, resets the word every time insted of letting
        //this bigram chain flow from one word to another.
        String currentWord = newdata[rand.nextInt(0, newdata.length)];


        System.
out
.print(currentWord + " ");
    for (int j  = 0; j < newdata.length - 1; j++) {
        if (newdata[j].equals(currentWord)) {
            currentWord = newdata[j + 1];
            System.
out
.print(currentWor
d +  " ");

        }
    }



    }
}

I created a little bigram model using two for loops. I'm new to coding and have wanted to use my free time for something productive, so I started to learn how to code. Now that I'm getting better, I want to post something to show the progress. This model uses text as a string that is held within a container; the container then uses the variable wordslist and uses three methods on it. You can see what the I variable does, and J variable has a Universal Set (U) = {1,2,3} (three numbers). {a,b,c} three index positions. [a = 0, b = 1....] b = (length - 2), because (length < -1) J = {1,2} {a,b,c} = (a,b-c). mport java.util.Random; import java.util.Scanner;

1 Upvotes

1 comment sorted by

1

u/Available_Safe1818 1d ago

You don't even use 'input'.