title: How can I repeat a public class in Java?
body: <p>I looked for a long time for a possibility to repeat a public class in Java, I found a solution with continue and repeating an additional while loop. But I am really not happy with it, is there a simpler method do to this? 
  Thanks for the help guys. </p>
  
  <pre><code>import java.util.Random;
  import java.util.Scanner;
  
  public class Zufallszahl {
  
      public static void main(String[] args) {
          while (1 == 1) { 
              Random rn = new Random();
              Scanner numberScan = new Scanner(System.in);
              Scanner restartScan = new Scanner(System.in);
              int zahl = rn.nextInt(100 - 1) + 1;
              int number = 0;
              String restart = "";
              int a = 0;
  
              while (number != zahl) {
                  a++;
                  System.out.print("Rate eine Zahl zwischen 0 und 100: ");
                  number = numberScan.nextInt();
                  if (number == zahl) {
                      System.out.println("richtig");
                      System.out.println("Du hast " + a + " Versuche gebraucht!");
                      System.out.print("Nochmal? j/n: ");
                      restart = restartScan.nextLine();
  
                  }
                  if (number &lt; zahl) {
                      System.out.println("zu klein");
                  }
                  if (number &gt; zahl) {
                      System.out.println("zu gross");
                  }
  
              }
              if (restart.equalsIgnoreCase("j")) {
                  continue;
              } else if (restart.equalsIgnoreCase("n")) {
                  System.out.println("Tschüss!");
                  return;
              }
          }
  
      }
  }
  </code></pre>