import java.util.*;

// fill in an array with random integers

public class RandomStringBuffers {

    public static void main (String [] args)  {
	// create the array
	StringBuffer [] sb = new StringBuffer[9];
	StringBuffer monkeys = new StringBuffer("n little monkeys");
	Random r = new Random();

	// read the elements
	for (int i = 0; i < sb.length; ++i) {
	    monkeys.deleteCharAt(0);
	    sb[i] = monkeys.insert(0,r.nextInt(10));
	}

	// print out the elements to check:
	for (int i = 0; i < sb.length; ++i) {
	    System.out.println("sb[" + i +"] = " + sb[i]);
	}	
    }
}


This is an example from CSci 1211 course.

The views and opinions expressed in this page are strictly those of the page author. The contents of this page have not been reviewed or approved by the University of Minnesota.