jeudi 21 mai 2020

(Java) How do i make those loops generate a new string every time?

Ok, so "hoehe" and "breite" are two ints that are grabbed from console input earlier. This works flawlessly. Now I want it to generate a random String with the lenght being the value of "breite", print that out and then do that "hoehe" times. The only Characters the string can have are / and \. Right now it generates the string one time and then prints it out "hoehe" times. I know why it does that, but have no Idea how to fix it.

        int i = 0;
    int y = 0;
    double rand;
    String output = "";
    String case1 = "/";
    String case2 = "\\";
      while (y < hoehe) {
        while (i < breite) {
          rand = Math.random();
          if (rand < 0.5) {
            output += case1;
          }
          else {
            output += case2;
          }
            i++;
        }
        System.out.println(output);
        y++;
      }



Aucun commentaire:

Enregistrer un commentaire