Advertisement
Guest User

Untitled

a guest
Oct 20th, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.13 KB | None | 0 0
  1. package com.example.helloworld;
  2.  
  3. import java.util.Random;
  4.  
  5. public class HelloWorld {
  6.     public static void main(String []args){
  7.         Random rand = new Random();
  8.  
  9.         String substring = "";
  10.         String polynom = "";
  11.         int index, length = 0;
  12.  
  13.         String[] letters = {"a", "o", "n", "t"};
  14.  
  15.         for (int j = 0; j < 10; j++)
  16.         {
  17.             int polynomLength = rand.nextInt(11); // generate a polynom length 0 - 10
  18.             for (int i = 1; i < polynomLength; i++)
  19.             {
  20.                 index = rand.nextInt(4); // 0 - 3
  21.                 polynom = letters[index] + polynom + letters[index];
  22.             }
  23.  
  24.             if (rand.nextInt(2) == 1) //50% chance to add a letter to the middle of the polynom
  25.             {
  26.                 index = rand.nextInt(4); // 0 - 3
  27.                 //otto
  28.                 //4 / 2 = 2
  29.                 //0 1 2 3
  30.                 length = polynom.length();
  31.                 polynom = new StringBuffer(polynom).insert(length/2, letters[index]).toString();
  32.             }
  33.             System.out.println(polynom);
  34.             polynom = "";
  35.         }
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement