Results 1 to 3 of 3
  1. #1
    lazarat is offline Member
    Join Date
    Sep 2012
    Posts
    13
    Rep Power
    0

    Default random letters generator JAVA

    I need generate an eye chart of random letters based on a user’s input. First I need to prompt the user for the number of rows and columns of letters to display. Then I need to generate and sopl random, capital letters formatted in rows and columns. Each letter needs to be separated in single spaces.
    Logic tells me that to do so , I first need to 1: Build an array with all alphabet chars. Step 2: Use a simple loop to select+remove letters from the array, and store in a new array. Step 3: Use your randomly selected characters in the eye chart. thing is, how to do that in java language...

    public class LetterGenerator {

    public String generateLarge() {
    String letter = null;
    int randomNum = (int) (Math.random() * 25);

    if (randomNum == 0) {
    letter = "A";
    } else if (randomNum == 1) {
    letter = "B";
    } else if (randomNum == 2) {
    letter = "C";
    } else if (randomNum == 3) {
    letter = "D";
    } else if (randomNum == 4) {
    letter = "E";
    } else if (randomNum == 5) {
    letter = "F";
    } else if (randomNum == 6) {
    letter = "G";
    } else if (randomNum == 7) {
    letter = "H";
    } else if (randomNum == 8) {
    letter = "I";
    } else if (randomNum == 9) {
    letter = "J";
    } else if (randomNum == 10) {
    letter = "K";
    } else if (randomNum == 11) {
    letter = "L";
    } else if (randomNum == 12) {
    letter = "M";
    } else if (randomNum == 13) {
    letter = "N";
    } else if (randomNum == 14) {
    letter = "O";
    } else if (randomNum == 15) {
    letter = "P";
    } else if (randomNum == 16) {
    letter = "Q";
    } else if (randomNum == 17) {
    letter = "R";
    } else if (randomNum == 18) {
    letter = "S";
    } else if (randomNum == 19) {
    letter = "T";
    } else if (randomNum == 20) {
    letter = "U";
    } else if (randomNum == 21) {
    letter = "V";
    } else if (randomNum == 22) {
    letter = "W";
    } else if (randomNum == 23) {
    letter = "X";
    } else if (randomNum == 24) {
    letter = "Y";
    } else if (randomNum == 25) {
    letter = "Z";
    } return letter;
    }
    Last edited by lazarat; 10-08-2012 at 05:52 AM.

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default Re: random letters generator JAVA

    Fubarable told you about the code tags in your earlier thread. Please don't make us remind you to use them every time you post code.

    Kindly edit your post and add the tags.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    penguinCoder is offline Member
    Join Date
    Oct 2012
    Location
    Tempe, Arizona
    Posts
    77
    Blog Entries
    12
    Rep Power
    0

    Default Re: random letters generator JAVA

    First you need to start off with asking the user for all the input. Ask them for the number of rows and the number of columns. Next use these values to create a 2 Dimensional Array.

    Java Code:
    char[][] eyeChart = new char[nRows][nColumns];
    After that use a nested for loop, along with your huge if statement to fill up the 2D-Array with random letters for each index.

    Java Code:
    for(int ix=0; ix<nRows; ix++){
      for(int ixx=0; ixx<nColumns; ixx++){
    
        int num = randomNum.nextInt(25);
      
        .....huge if statement compared against num.....
    
        eyeChart[ix][ixx] = letter;
      }
    }
    Then to display your code, just use the same concept of the nested for loops.

    PS
    I barely glanced at any of your code due to the fact that it is not formatted, so my variables might not match up to what you got. Use the code tags man, it makes it so! much easier to read. Hopefully I didn't give a way to much of what you were suppose to do, because Fubarable will delete me in a heartbeat if I did... :)
    Last edited by penguinCoder; 10-08-2012 at 05:03 PM.

Similar Threads

  1. print random letters(LinkedList)
    By nickdimi in forum New To Java
    Replies: 4
    Last Post: 12-21-2011, 09:31 PM
  2. Help with random letters.
    By jenxin in forum New To Java
    Replies: 110
    Last Post: 02-28-2011, 03:32 PM
  3. Random Generator
    By Learning Java in forum New To Java
    Replies: 9
    Last Post: 05-31-2010, 08:15 PM
  4. Generate a random code 4 letters long
    By bl00dr3d in forum New To Java
    Replies: 9
    Last Post: 04-06-2009, 05:32 AM
  5. Random Generator
    By padutch2 in forum New To Java
    Replies: 1
    Last Post: 12-03-2007, 06:43 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •