Sunday, September 28, 2014

How to Write a Blurb With a Java Program

Instructions

    1

    Set up a Blurb class. This class will contain a String array, which will contain the blurbs, as well as a counter to count the number of blurbs:

    import java.io.*;
    import java.util.Random;

    class Blurb

    String[] blurbs = new String[20];

    int count = 0;

    public static void main(String args[])


    2

    Create a list of blurbs in an array:

    public static void main(String args[])

    blurbs[0] = "blurb 1";
    blurbs[1] = "blurb 2";
    blurbs[2] = "blurb 3";
    blurbs[3] = "blurb 4";

    count = 4; //four blurbs

    3

    Generate a random number in the main program:

    Random r = new Random(); //random number up to

    4

    Cycle through the blurbs at short intervals, using a random number each time:

    for (int i = count; i < count; i++)
    int current = r.nextInt(count); //random number between 0 and 3
    System.out.println(blurbs[current]);

    Thread.sleep(10000); //pause for ten seconds



No comments:

Post a Comment