Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.helloworld;
- import java.util.Random;
- public class HelloWorld {
- public static void main(String []args){
- Random rand = new Random();
- String substring = "";
- String polynom = "";
- int index, length = 0;
- String[] letters = {"a", "o", "n", "t"};
- for (int j = 0; j < 10; j++)
- {
- int polynomLength = rand.nextInt(11); // generate a polynom length 0 - 10
- for (int i = 1; i < polynomLength; i++)
- {
- index = rand.nextInt(4); // 0 - 3
- polynom = letters[index] + polynom + letters[index];
- }
- if (rand.nextInt(2) == 1) //50% chance to add a letter to the middle of the polynom
- {
- index = rand.nextInt(4); // 0 - 3
- //otto
- //4 / 2 = 2
- //0 1 2 3
- length = polynom.length();
- polynom = new StringBuffer(polynom).insert(length/2, letters[index]).toString();
- }
- System.out.println(polynom);
- polynom = "";
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement